All Questions
78 questions
1
vote
1
answer
91
views
Reverse a sublist of a singly-linked master list in constant space and maximum of one pass (Java)
So I found this funky programming challenge somewhere on Quora. The idea is to take the head of a singly-linked list, and reverse a specific sublist. The requirements are:
runs in constant space,
...
6
votes
3
answers
932
views
Ordered squares of an ordered integer array
I had this question in an interview recently.
Given a sorted array of integers, return a list of those integers squared, with the squares sorted. So given an array of these numbers:
...
7
votes
5
answers
736
views
String combinations of 0 and 1
I was asked this question in an interview:
Given a string s consisting of 0, 1 and ...
1
vote
2
answers
976
views
Leeetcode - Best time to buy and sell stock to get maximum profit
Question
Say you have an array for which the ith element is the price of a
given stock on day i.
If you were only permitted to complete at most one transaction (i.e.,
buy one and sell one ...
2
votes
1
answer
1k
views
Implement Queue using fixed size array
I came across below interview question and I am working on it:
Build a queue class with the enqueue and dequeue methods. The queue
can store an UNLIMITED number of elements but you are limited to
...
4
votes
2
answers
2k
views
Trip planning algorithm
I was presented with an interview question described as follows:
Receiving an int[] A of cities, where each A[i] has an appeal ...
3
votes
1
answer
2k
views
Counting subtrees where all nodes have the same value
A unival tree (which stands for "universal value") is a tree where all
nodes under it have the same value.
Given the root to a binary tree, count the number of unival subtrees.
For example,...
3
votes
1
answer
3k
views
Family Relationship Tree
Developer Assignment - Family And Relations
Going through the old stuff in his attic, Indiana comes across a chart
which looks like a family tree of multiple generations which shows his
...
1
vote
1
answer
142
views
Solving a multi variable polynomial
For this equation, I need to count possible solutions:
$$ a + b^2 + c^3 + d^4 \le S $$
$$0\le a,b,c,d \le S$$
I tried the following approach:
...
2
votes
1
answer
55
views
Find the highest result between two elements in an array using their values and indices
I got a programming question on an interview where performance was the focus. I couldnt come up with a better solution than the one below which I think has a time complexity of O(n^2 + n) and scored ...
2
votes
2
answers
423
views
Find kth smallest element in binary search tree
I was faced with below interview question today and I came up with below solution but somehow interviewer was not happy. I am not sure why..
Given a binary search tree, find the kth smallest element ...
3
votes
1
answer
252
views
Map Character to Characters Most Frequently Found With it (in list of strings)
For an interview, I was tasked with writing a program that consumes a list of strings, and produces a mapping between every character in the list, and the characters found most frequently with it (let'...
1
vote
2
answers
946
views
String Compression
Implement a method to perform basic string compression using the counts
of repeated characters.
For example, the string "aabcccccaaa" would become "a2b1c5a3". If the
"...
0
votes
0
answers
7k
views
Find the shortest path between two points in a 2D matrix with obstacles
I need to find shortest path between two points in a grid given an obstacles..
Given a 2 dimensional matrix where some of the elements are filled
with 1 and rest of the elements are filled. Here X ...
0
votes
2
answers
91
views
Given an integer number, invert its bits. You cannot use the ~ operator
Here is my code:
...