Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
3 votes
1 answer
209 views

Searching an element in a 2D sorted array

I had to write a code (as an exercise) that receives a 2D row wise and col wise sorted array and an element, and return true is the element exists in the array. The first thing that came to mind when ...
RedYoel's user avatar
  • 311
8 votes
1 answer
216 views

An array with \$O(\log\ n)\$ time complexity for all operations

Does this exist already? It's an array (=variable-size list with integer indices) where add/remove/set and get all take \$O(\log\ n)\$ time. I couldn't find this anywhere, so I made up the name "Log-...
Stefan Reich's user avatar
3 votes
2 answers
4k views

Finding unpaired number in an odd length Array of integers

codility OddOccurrencesInArray: A non-empty array A consisting of N integers is given. The array contains an odd number of elements, and each element of the array can be paired with another element ...
Anirudh's user avatar
  • 872
0 votes
1 answer
1k views

Sort multidimensional array based of the difference in the value

Sort multidimensional array based of the difference in the value, if value is same sort on first column. Constrains: No of rows can be any but fixed no of column ie 2. Example: <...
Sandesh Wani's user avatar
2 votes
1 answer
1k views

Find all pairs in an array whose absolute difference equals x

I have an array A of integers with n values and an integer x. I need to find all the pairs in that array whose absolute ...
user_1703224's user avatar
1 vote
1 answer
93 views

Given an array of integers, find and print its number of negative subarrays on a new line

Given an array of N integers, find and print its number of negative subarrays (i.e sub arrays having negative summation) on a new line. My code is taking \$\mathcal{O}(n^2)\$ time. How can I improve ...
user2769790's user avatar
4 votes
1 answer
2k views

Lexicographically smallest wave like array without sorting

Given an array of integers, sort the array into a wave like array and return it. In other words, arrange the elements into a sequence such that a1 >= a2 <= a3 >= a4 <= a5..... Example: Given [1,...
clever_bassi's user avatar
5 votes
2 answers
8k views

Find the number of K-Complementary pairs in an array

Below is the program to find k-complementary pairs: K = A[i] + A[j];. ...
SiddP's user avatar
  • 153
1 vote
1 answer
801 views

Finding a max element in an array in Java

Created the following method: ...
PacificNW_Lover's user avatar
10 votes
2 answers
471 views

Min sub array size with a given sum

How can the time complexity of the following code be improved (assuming it's \$O(N^2)\$)? What about style and patterns? This code is trying to find the minimum subarray size that adds up to given sum ...
Mona Jalal's user avatar
2 votes
2 answers
685 views

Finding number of number pairs with given difference [closed]

pairs() is a function which returns the total number of combinations whose difference is k. ...
Rahul Singh's user avatar
8 votes
2 answers
5k views

Finding the count of negative sub-arrays for a given array

I want to improve my implementation for the following problem: You are given an array of n integers. A sub-array is "Negative" if sum of all the integers in that ...
John Doe's user avatar
  • 245
7 votes
2 answers
1k views

Finding pairs of numbers within A that add up to N

I am working on an interview question from Amazon Software Interview: Given an integer N and an array of unsorted integers A find all pairs of numbers within A which add up to N I have a working ...
committedandroider's user avatar
1 vote
4 answers
384 views

Finding the second largest element of large input sets

I have a problem where I need to find the second maximum element of the user inputs. It's an online practice problem and I can't figure out why the server responds back with a Non-Zero Exit Code error ...
arindrajit's user avatar
0 votes
4 answers
7k views

Finding all integers in an array with odd occurrence

I am doing an interview exercise problem from here. The problem is to find "all numbers that occurred an odd-number of times in an array". Here is my high level psuedo code thinking: Construct a map ...
committedandroider's user avatar

15 30 50 per page