Skip to main content

All Questions

Tagged with
4 votes
3 answers
761 views

Determine whether two arrays have the same elements with the same multiplicities

I have written a Python function called comp that checks whether two given arrays have the same elements, with the same multiplicities. The multiplicity of a member ...
TAHER El Mehdi's user avatar
1 vote
1 answer
58 views

Optimizing the Dig Pow function

I have written a Python function to solve the Dig Pow problem, where the goal is to find a number k such that the sum of each digit of n raised to a specific and ...
TAHER El Mehdi's user avatar
1 vote
0 answers
158 views

Smallest interval whose sum exceeds a threshold

In a non-negative 1D array x, we wish to find the shortest slice such that x[start:end] > threshold, with constraint that <...
OverLordGoldDragon's user avatar
3 votes
1 answer
848 views

Divide array into three disjoint sets with equal sum

Problem definition : Array partition problem Given an array of positive integers, divide it into three disjoint subsets having equal sum. These disjoint sets cover the complete array. Example Input: [...
nkvns's user avatar
  • 389
10 votes
4 answers
3k views

First non-repeating Character, with a single loop in Python

I recently tried to solve the first non-repeating character problem. Please tell me if my solution is valid. I'm aiming for O(n) with a single loop. My thinking is, it would be easy to tell you what ...
zing's user avatar
  • 203
13 votes
5 answers
2k views

Array manipulation: add a value to each of the array elements between two given indices

This is a Hackerrank problem: https://www.hackerrank.com/challenges/crush/problem You are given a list of size \$N\$, initialized with zeroes. You have to perform \$M\$ operations on the list and ...
jeremy radcliff's user avatar
7 votes
2 answers
815 views

Number of occurrences of strings in array

This is a Hackerrank problem (https://www.hackerrank.com/challenges/sparse-arrays/problem). We're given an array of strings and an array of queries, and have to return an array of the number of ...
jeremy radcliff's user avatar
7 votes
1 answer
210 views

Computing sums of weird pattern in 2D array as efficiently as possible

This is a problem from Hackerrank (https://www.hackerrank.com/challenges/2d-array/problem). We're given a 6x6 (always) 2D array and asked to compute the sums of all the hourglass patterns in the array....
jeremy radcliff's user avatar
15 votes
6 answers
2k views

Return first duplicate

This is a problem from Codesignal. The guaranteed constraints are 1 <= a.length <= 10^5, and 1 <= a[i] <= a.length. ...
jeremy radcliff's user avatar
8 votes
2 answers
776 views

Optimize function that returns length of a subarray

I did an exercise today on where the task is to write a function that returns the length of the longest subarray where the difference between the smallest and biggest value in the subarray is no more ...
hopla's user avatar
  • 191
3 votes
3 answers
657 views

Given an array, find all its elements that can become a leader

I was successful in solving a challenge in codility, but my solution failed performance tests. How can I improve my solution? Challenge: Integers K, M and a non-empty array A consisting of N ...
Harith's user avatar
  • 131
1 vote
2 answers
506 views

Maximum contiguous sum in an array

The following code is my solution for the following Daily Coding Challenge Given an array of numbers, find the maximum sum of any contiguous subarray of the array. For example, given the ...
MrJoe's user avatar
  • 2,133
5 votes
1 answer
5k views

Find if one list is a subsequence of another

So the problem of verifying if a list is a subsequence of another came up in a discussion, and I wrote code that seems to work (I haven't rigorously tested it). IsSubequence.py ...
Tobi Alafin's user avatar
  • 1,792
2 votes
2 answers
173 views

Recursive Transversal (Python)

For a programming challenge I was doing, I needed to traverse a list of lists, and while writing the standard 2D traversal function, I thought why not generalise it, so I did. Here's my best effort: ...
Tobi Alafin's user avatar
  • 1,792
2 votes
1 answer
2k views

Rotate matrix 90 degrees

I recently did problem 1.7 Rotate Matrix in Cracking the Coding Interview. I realized my code is very different than what is in the book and also from what I'm finding online (I'm having trouble ...
stillearning's user avatar

15 30 50 per page