Kallu
BAN USER
- 1of 1 vote
AnswersGiven a array of numbers and a number N. Find out all combinations of 3 numbers in array whose sum is N.
- Kallu in India
Genarally, there is a common similar problem to find all possible pairs whose sum is given number. Now the problem extention to this. Find all possible 3 numbers whose sum is given number.| Report Duplicate | Flag | PURGE
Software Engineer / Developer Algorithm
Hey guys, I strongly feel except Ehsan, nobody has understand question properly. Come on, its Amazon question. Interviewer has just given one example. It doesn't mean that we have write program for just for that example.
Given numbers can be in any range (single digit, double and to any extent) and can be mixed digit numbers too (like can start with 2 digit number and can go to 3 digit number: Below sample inputs can help you to understand question better:
123567 // 1 digit numbers
45464849 // 2 digit numbers
9899100102103 // mixed digit numbers
Refer Question id=5564407157358592
Hope this helps
Will maintain size variable separately, so that we don't need to bother about which stack is empty/full.
Enqueue:
If (not overflow)
push to S1
Dequeue:
If(not underflow) {
If(S2 is not empty)
Pop from S2
Else
Pop all elements from S1 and push to S2. Finally Pop from S2
Is it not simple
- Kallu September 19, 2013We don't bother about pre-processing (constructing dictionary). In problem it is mentioned that a function() is available which gives us whether the word is in dictionary or not. So, this is out of problem scope.
Now coming to actual problem, I vote for recursion + dynamic programing APPROACH which is given by thomoscom136.
I would prefer to have predefined number of 2s for a range (lets less than 100 and less 1000 etc). The max input is just max of unsigned long or so. So, result can give in constant time (limited number of iterations). But this approach needs quite number of condition checks
- Kallu August 02, 2013@Ashish, If I understand your solution correctly, it replaces element with next greater element on right side. But problem is is element should be replaced with NEAREST GREATER element.
Correct me if I am wrong.
Input: 22 5 4 20 13 17 12 3
Output: 22 7 7 20 17 17 12 3
I also didn't understand why people are replacing with -1. If we don't have greater element on right side, I believe we should keep that element as it is. am I right?
Repjoycejflora, Android Engineer at ABC TECH SUPPORT
I am excited about cooperation and interesting projects. Last year I work for a person who provides the black magic ...
Repsushiplarson, Animator at Achieve Internet
Hi, I am a creative Assistant Video Editor with experience in all aspects of video production. Working at a post-production ...
RepHi, I am Alisa from Southfield, USA, I am working as a Toolmaker in an Audio-Visions company. I am also ...
Repjonej8821, Blockchain Developer at Alliance Global Servies
I am EbonyTuckson .I am a teacher who works in High school. I work during school hours but may also ...
Repharoldknopph, Android test engineer at AMD
I am a publicity writer from Atlanta USA . I create an intended public image for individuals, groups, or organizations. I ...
I don't find any challenge here. I could do it as in-line alogorithm and that too in one iteration. Please let me know, if you have any input which breaks this program.
Is it really Amazon question? :)
Algorithm:
1. Find out input char position in given string
2. If char is not found then don't do anything. Just return
3. From that position (found in step1), keep copying all chars one position back(left) till end of the string.
- Kallu September 22, 2013