All Questions
15,279
questions
0
votes
1
answer
39
views
Kotlin data structure for efficient lookup of nested data
I am currently working on an application that needs to create a mapping between document pdfs and corresponding JSON data files. The files are coming from a third party so I have no control over their ...
0
votes
2
answers
55
views
How is my algorithm for stock span problem incorrect?
The question :
The stock span problem is a financial problem where we have a series of n daily price quotes for a stock and we need to calculate the span of stocks price for all n days.
The span Si of ...
0
votes
2
answers
89
views
Finding if strings can be anagrams
I have String s1 and String s2. I want to check whether it is possible to make s1 an anagram of s2 by removing a single character zero or more times from s1, and removing a single character zero or ...
-1
votes
1
answer
72
views
Shuffle the Array - LeetCode problem. 2 pointers approach fails [closed]
I am trying to solve LeetCode problem 1470. Shuffle the Array:
Given the array nums consisting of 2n elements in the form [x1,x2,...,xn,y1,y2,...,yn].
Return the array in the form [x1,y1,x2,y2,...,xn,...
1
vote
1
answer
55
views
Java DepthFirstSearch Algorithm not working
I have tried to code a depthfirstsearch algorithm to solve a maze. This is what I have so far. I have tried to add as much detail so the logic is understandable:
//Upgraded dfs algorithm that creates ...
0
votes
2
answers
123
views
Finding minimum value in given range efficiently
I have function that takes a number n that represents number of servers and another parameter represents a list of requests
Initially servers will hold values 0 of size n.
For each request, requests[i]...
-1
votes
2
answers
96
views
Flip consecutive zeroes to ones in k operations to have maximum number of ones, find the maximum number of ones
You are given a binary string made of 0 and 1, and a value k which represents number of operations. You can flip consecutive 0s in each operation to 1s. Find the maximum number of 1s after k ...
-1
votes
2
answers
141
views
Finding minimum pairs from given input
I have a string s of length n made of only 3 characters 0, 1, and !, and two numbers provided as x and y
Now I have to replace ! with 0 or 1
Then count number of subsequences 01 say count1 and also 10 ...
-2
votes
0
answers
112
views
Remove unncessary parentheses in Java
I am trying to remove unncessary parentheses in an expression. So far, my code handles most of the use cases such as,
Expression: 2 + (3 / -5) Result: 2 + (3 / -5)
Expression: x+(y+z)+(t+(v+w)) Result:...
-1
votes
1
answer
87
views
Count the valid segments for input array of numbers
I have an array of numbers of size n, I want to count the segments, (which are subarrays of size 3 or more) based on below condition:
arr[left] = arr[right] = sumOfItems[left+1, right-1],
it means ...
0
votes
2
answers
145
views
Find unique or combination for given array
I have an array of numbers of size n, select all possible distinct increasing subsequence of the array, for each subsequence find the bitwise OR value and return them as result in increasing order.
...
1
vote
1
answer
83
views
minimum changes needed in array to make contiguous elements sum same
This question is asked during an online interview:
There is a service with n servers and the i'th server has a processing power of server[i] units.
A user can assign k different tasks to any ...
3
votes
1
answer
165
views
How do you represent quaternion rotations in 2 dimensions?
I'm developing in Android Studio Java with two Bluetooth IMUs that give quaternions. The sensors are oriented in the following way to start:
In the image shown, this is considered the “zero” position....
4
votes
2
answers
269
views
Minimum edges to form path with length L
I came across this problem.
Given a weighted tree T, find the minimum number of edges to form a simple path (no duplicate vertices or edges) of weight (sum of weights of edges) exactly L.
More ...
2
votes
1
answer
56
views
Topological Sort as Reverse Post-DFS | Course Schedule II LeetCode
Currently solving Course Schedule II on LeetCode and this is the code that DOES NOT pass all test cases because of the following line: Collections.reverse(postOrder);. Removing this line solves all ...