NoOne
BAN USERLook at that link there? That is the language we have created.
 1of 1 vote
AnswerSuppose there is a function given to you that:
def get_friends( person_id ) { /* returns friends of person */ }
How you are now going to recommend friends to a person based on number of mutual friends? So, come up with the function:
 NoOne in Indiadef friend_reco( person_id, max_no_of_friends ){ }
 Report Duplicate  Flag  PURGE
Amazon SDE3 Algorithm  0of 0 votes
AnswersGiven billions of Identity cards of the form :
card : { my_id : "my id", "moms_id" : "mom id", "dad_id" : "dads id" }
If one gives you two Person's id, how can you tell if these 2 persons are blood related.
So, write a function that is:
 NoOne in Indiadef is_blood_related( person_id_1, person_id_2 ) // go on..
 Report Duplicate  Flag  PURGE
Amazon SDE3 Algorithm  2of 2 votes
AnswersGiven an unsorted array of integers, find the length of the longest consecutive elements sequence.
 NoOne in India
For example,
Given [100, 4, 200, 1, 3, 2],
The longest consecutive elements sequence is [1, 2, 3, 4].
Return its length: 4.
Your algorithm should run in O(n) complexity. Report Duplicate  Flag  PURGE
Uber Senior Software Development Engineer Algorithm  1of 1 vote
AnswersThe stock exchanges work with price matching. A seller comes with a price, and a buyer, given asking for the exact same price are matched, and in quantity.
 NoOne in India
Design a system that works.
Considerations:
1. More than a million buy/sale happens in a second.
2. One needs to show a ticker prices  last sold price of a stock. Report Duplicate  Flag  PURGE
Myntra Software Architect Algorithm  0of 0 votes
AnswersCreate a data structure that stores integers, let then add, delete. It also should be be able to return the minimum diff value of the current integers.
 NoOne in India
That is,
min_diff = minimum (  x_i  x_j  )
Example:
1,3,4,10,11,11
min_diff = 0
1,3,4,10,11,14
min_diff = 1 Report Duplicate  Flag  PURGE
Uber Senior Software Development Engineer Algorithm  0of 0 votes
AnswersThe original question can be found from here :
 NoOne in India
franklinchen.com/blog/2011/12/08/revisitingknuthandmcilroyswordcountprograms/
Read a file of text, determine the *n* most frequently used words, and print out a sorted list of those words along with their frequencies.
In the same spirit of the history:
1. Do it using pure shell scripting
2. Do it in the favourite language of your choice
Try to minimise code and complexity. Report Duplicate  Flag  PURGE
Deshaw Inc Software Developer Algorithm  0of 0 votes
Answer1. If I say quick sort takes O(e^n ) on the average, would I be wrong?
 NoOne in India
2. Do you think O( f ) is a good idea for real engineering?
3.Given a choice, what other 'order of' measure would you propose to use ?
4. Do you see a real problem with the modified *order of* ?
5. If you were to sort 10 elements, what sorting method would you have used?
6. If you were to sort 1 trillion unicode characters, what sorting method you would have used? Report Duplicate  Flag  PURGE
Microsoft SDET Algorithm Math & Computation  0of 0 votes
AnswersThe actual problem from question?id=6289136497459200
Implement pow, with :// Assume C/C++, as of now double pow ( double x, double power )
No library functions allowed.
Should return : x^power
=== Edit ===
People took it a bit trivially, thus examples should help :
 NoOne in United Statesx = pow ( 4, 0.5 ) // x = 2.0 x = pow ( 8, 0.333333333 ) // 1.99999999986137069 x = pow ( 10.1 , 2.13 ) // 137.78582031242644
 Report Duplicate  Flag  PURGE
Microsoft SDET Algorithm  0of 0 votes
AnswersFrom here : question?id=5660692209205248
 NoOne in United States
Inorder traversal:
A>B>C>D>E>F>H>L>MP>R>S>T
Write a function (pseudocode is fine) that given a starting node, advances to the next inorder node in a binary tree.
Please also provide a datastructure definition of a node. Report Duplicate  Flag  PURGE
Arista Networks Software Developer Algorithm Trees and Graphs  0of 0 votes
AnswersApparently DESCO asked it. It was faulty, and I am fixing it. The physics was wrong. A mono pole is an abstract magnet with either the north or the south pole of the magnet.
[ en.wikipedia.org/wiki/Magnetic_monopole ]
Imagine you are given such *n* monopoles, all of the same type, say North type. Thus, all of these repel one another. The force of repulsion follows inverse square law :
[ en.wikipedia.org/wiki/Inversesquare_law ]
That is, given two such monopoles with a distance *r* between them, the force of repulsion between them is given by :F = ( 1.0 ) / ( r ** 2 )
Now, suppose you are also given an array of *n* number of positions over X axis, like : [ 0, 1, 4, 10 , 21 , .. ] where you need to place the monopoles ( imagine they are hold tight there, and do not move away ).
 NoOne in United States
After placement, you are given another monopole, of different type S, say. Find positions to place the monopole so that it is stable.
Fixes from the original question :
[geeksforgeeks.org/deshawinterviewexperienceset19oncampus/ ]
1. Monopoles exhibit inverse square law, not inverse law.
2. It is impossible to have stable configuration using same type monopole, so one must use another type, repulsion is not stable, attraction is.
( Terrible physics mistakes )
PS. Do not try to do binary search here. Binary search assumption is underlying linearity of the structure, thus, effectively there are proportionate elements in left and right. In the classic cases of sorted array, the expectation is 50/50. But here due to non linearity (inverse square) , it won't work. Report Duplicate  Flag  PURGE
Deshaw Inc Software Developer Algorithm  0of 0 votes
AnswersGiven a set of numbers, find out all subsets of the set such that
the sum of all the numbers in the subset is equal to a target number.s = [ 1, 2, 3, 4, 5 ] target = 5 op = [ [ 1,4 ] , [2,3] , [5] ]
Application: Given a fixed budget, and work items we are doing back filling to check what all we can attain with the budget.
Continuation. Imagine the set is actually a set of work items, with cost and utility involved :def work_item : { name : 'foo bar' , cost : 10 , utility : 14 }
Now, solve this to maximise utility.
Continuation. Imagine that the work items are related, so that, if work item w1 is already in the
subset of the work items selected, w2 's utility increases further!.
( Can you imagine how it can happen? Effectiveness of Mesi increases when he plays for Barca)
So, you are given a list like this :w1 > normal utility 14, with w2 20, ....
Now maximize payoff.
NOTE: Payoff is a matrix. This comes from game theory.
Hence, a payoff matrix looks like :w1 w2 w3 w4 .... w1 w1 w2 w2 w3 w3 w4 w4
A cell ( i,j) is filled up with if a list contains both wi and wj, then how much the payoff would be. It is a symmetric matrix.
 NoOne in United States Report Duplicate  Flag  PURGE
Amazon SDE3 Algorithm  0of 0 votes
AnswersWe tend to use computer to solve practical problems that actually earns or save dollars. Here is something that happens across the stock exchanges : people buy and sell stocks.
 NoOne in India
We generally use automated intelligent systems to buy and sell stocks. That part is too much mathematics, and beyond scope of this interview. There is another part. Suppose the system issues a buy order : buy 1000 Microsoft stock. Now, there are more than 1 ( in fact 10 ) active exchanges from where we can buy MSFT. There is a slight price delta, which keeps changing over time. There is another problem. In each stock exchange, prices are stacked, that is :
1. For first 100 stocks prices are 55$.
2. Next 200 stocks, prices are 55.2$.
... etc, and you got the idea. Even this stacks are changing over time.
Thus, here is the problem to solve. Design and implement a system such that one can buy n stocks with minimal price.
Also, in the same spirit, the same system should be able to sell n stocks with maximum payoff possible.
This is a non trivial problem, for Quant systems.
There are always k no of exchanges to hit. Report Duplicate  Flag  PURGE
Goldman Sachs Software Engineer / Developer Algorithm Cache Computer Architecture & Low Level Computer Science Distributed Computing Large Scale Computing Math & Computation Software Design  0of 0 votes
AnswersAs you know, Computers were invented to solve practical business problems, we tend to ask practical applied questions. One of the key areas where we want to apply computers is simulation. As most of the people working in software are Engineers, here is the problem. It is called 3 body problem.
 NoOne in India
3 Bodies with masses [ m1, m2, m3 ] are initially positioned in the 3 points in the space, thus, having positions [ P1, P2, P3 ].
Observe that each Pi is nothing but [ xi, yi, zi ].
Once the initial condition is set, definitely gravity would work and they would start falling against each other. Write code to simulate this problem. Imagine G, the constant of gravity as 1.
How do you go about simulating it?
Hint : feynmanlectures.caltech.edu/I_09.html see 9.5
Face to face. Pen and Paper. Panel Interview, 2 person Panel. 60 Minutes. For Engineers only, was specifically told about it. Report Duplicate  Flag  PURGE
Software Developer Algorithm Computer Science Graphics Math & Computation Programming Skills  0of 0 votes
AnswersGiven a convex polygon ( is planer as opposed to a polytope) and a point one had to tell if the point lies inside the polygon or outside the polygon.
 NoOne in India
To understand convexity : mathopenref.com/polygonconvex.html
Thus the question comprise of 3 sub problems :
1. How to store a polygon.
2. How to define inside and outside of a polygon.
3. How to solve the actual one, given 1,2 ? Report Duplicate  Flag  PURGE
Deshaw Inc Software Developer Algorithm  0of 0 votes
AnswersAs you guys know, C did not have,and does not have anything called class. C++ has them. Now, C++ was written using C. In fact, C++ initially was called C with classes.
 NoOne in India
Thus, here is the problem for you.
Given you have C, and you need to implement class like behaviour, how you would do it? Specifically, implement the following in C :
1. A Simple Hello class with hello() function printing "Hello, World" .
2. A new operator which enables creating this constructor less class.
3. A delete operator that deletes the pointer.
How would you do it? Report Duplicate  Flag  PURGE
Deshaw Inc SDET C  0of 0 votes
AnswersLinux has this nice command called *tree*.
 NoOne in India
If you did not use it, please take a look around.
You do not have to write one. BUT, you have to do something similar. Given a file name ( not a path ), and an initial directory, you have to list all the file paths, which matches the file name, case should not be considered.
Also allow regex match.
Again, the problem is non trivial.
It was expected to ask the right questions. Report Duplicate  Flag  PURGE
SDET Algorithm Operating System  0of 0 votes
AnswersThere is this nice tiny *nix utility called *wc*.
The idea here is :wc file_name
prints :
 NoOne in India
character count of the file.
Word count of the file.
Line count of the file.
You have to implement your own *wc* program.
NOTE: The problem is non trivial for 3 reasons.
It was expected to ask about the non triviality. Report Duplicate  Flag  PURGE
SDET Algorithm Operating System  0of 0 votes
AnswersNone actually understands how garbage collection works, albeit people ask this in the interviews. Nonetheless, we are going to ask you something very similar. Here is the problem.
Take an array of bytes, perhaps 1MB in size.
Implement these two operations:ptr_structure = alloc ( amount_of_storage ) freeed = free ( ptr_structure )
Now, here is your problem. alloc must allocate contiguous storage. If it is not possible, you need to compact ( defragment ) memory. So, you need to implicitly write a :
defragment() // defragments memory
Worse is coming. Even imagining you have written a stop the world defragmenter, after you reallocate, how the ptr_structures would actually work?
 NoOne in India
Solve this whole problem.
Time allocated was 1 hour. Face to face, panel with 2 interviewers. Report Duplicate  Flag  PURGE
SDET Algorithm Assembly Computer Architecture & Low Level Computer Science Data Structures  0of 0 votes
AnswersImagine there are brick boulders, all of integer size.
Their sizes are stored in an array.
The figure looks something like this :
peltiertech.com/Excel/pix2/Histogram2.gif
Now, suppose someone is pouring water into it till water starts spilling.
You have to answer how much water the boulders are holding up.
 NoOne in Indiadef water_holding( arr ) { /* answer this */ }
 Report Duplicate  Flag  PURGE
Deshaw Inc SDET Algorithm  0of 0 votes
AnswersXPATH implementation problem.
 NoOne in India
Here is the problem.
Implement XPATH expressions, given there is a DOM tree :
1. $x('//*[text() = "abc"])
How do you think it is implemented? Write code, imagine you have a general purpose tree.
2. $x('//span[text() = "abc"])
How do you think it is implemented? Write code, imagine you have a general purpose tree.
Now, explain which one would be faster, and why?
Explain from the design and the code you have written. Report Duplicate  Flag  PURGE
SDET Algorithm Application / UI Design  0of 0 votes
AnswerAs you know, every OS comes up with this tiny application called the calculator. It is good. Now, here is our problem. If we try to implement the function
def calculate( operand, operator, operand ) { /* Do Interviewers bidding here */ }
I have to write if upon if upon if upon if to do for all operators. Moreover, some operators are not even binary! Take example the abs() or say the negate()!
 NoOne in India
Bigger problem persists. With the if mode, we can not even add operators as we wish to without changing code!
But that is a sin. So, what do we do? That is question 1.
In question 2, as a software tester, how do you propose to test and automate the above? Writing more if than the developer is not allowed. Report Duplicate  Flag  PURGE
SDET Algorithm Data Structures Object Oriented Design Programming Skills Software Design  0of 0 votes
AnswersWe all know databases are very very slow. In fact they are so slow that very serious people who wants to do volumes of read operation and search operations write their own implementation. In this question, you would be asked to do the same, for a very limited operation  select.
Every item stored has this field called timestamp.
Now, here is the problem you need to solve :select items where time < some_time select items where time < some_time and time < another_time select items where time > some_time
Imagine you have millions of data rows. How to store it in HDD, and how to load, entirely your problem. None is going to insert anything on existing data  only read.
 NoOne in India
Write an algorithm that solves this problem, and a data structure that works as storage for the data. Report Duplicate  Flag  PURGE
SDET Algorithm Database  0of 0 votes
AnswersImagine you are given the instructions :
GOTO <LABEL> WHEN <CONDITION> NOP ; no operation
Implement the following using it:
 NoOne in India
1. If condition.
2. If else condition.
3. If else if else condition.
4. While loop
5. for loop. Report Duplicate  Flag  PURGE
SDET Assembly  0of 0 votes
AnswersGiven brackets, e.g. '(' and ')' as the only symbols, write a function that would generate : true, if the brackets are matching, false if the brackets are not matching.
 NoOne in India
Almost everyone can do the above.
Now, prove that it works.
Also tell which class of grammar the string belongs to.
Showcase why your algorithm is a language recogniser for the same. Report Duplicate  Flag  PURGE
SDET Automata  0of 0 votes
AnswersYou are given 20 questions to solve in 20 minutes.
 NoOne in India
If you successfully solve the question, you would receive 2 marks.
If you failed to solve the question, and you do not try it ( let it untouched ) , you would receive 0 marks. If you solve it wrong ( i.e. not the correct answer )  you would receive 1 ( negative) .
With the story, here are the problems:
1. Write an algorithm, which, given an input array ( set ) of questions, and varying probability ( 0 <= p <= 1 ) of can do and can not do per question, generates a strategy for solving the paper to generate maximum expected pay off.
2. Given the question paper is multiple choice, between 4 choices ( a,b,c,d ) do a bias analysis ( e.g. if more a's are coming than 'c's ), and decide if you would like to probabilistically take risk and mark some to increase pay off.
Obviously, you can get a maximum 40, and a minimum 20.
3. Now, put yourself in the position of the examiner, and try to ensure it is almost impossible to increase payoff by random selection over the questions. Try to negate the bias. That is question 3.
In all 3 cases write an algorithm. Face to face interview, time allocated was 60 minutes. Panel Interview. Report Duplicate  Flag  PURGE
unknown SDET Algorithm  0of 0 votes
AnswersFind the n'th Ugly no. An ugly no. is defined as a no. which are of the form :
n = ( 2 ** p ) * ( 3 ** q ) * ( 5 ** r )
with p,q,r >= 0 and are integers not all equal to zero.
 NoOne in United States
You must not memorise the whole sequence, as n can be really large.
Hint : use number theory to figure out the pattern of the increasing sequence. Report Duplicate  Flag  PURGE
Algorithm  0of 0 votes
AnswersGiven an array, move the smaller no to the left and the larger nos to the right. The relative positioning between the small no's and the relative positions between the large nos should not change.
The original ( ill formulated ) question can be found here :
question?id=5756583549075456.
Example :a = [ 6 4 5 0 2 1 11 1 ] after_a = [ 0 , 2, 1, 1, 6, 4, 5, 11 ]
Note, for lack of good explanation, please do not laugh at the poster in the solutions. After all, they are trying to help or get help.
 NoOne in United States Report Duplicate  Flag  PURGE
Arrays
And we have Quora.
quora.com/Youhave1000winebottlesoneofwhichispoisonedYouwanttodeterminewhichbottleispoisonedbyfeedingthewinestotheratsThepoisonedwinetakesonehourtoworkHowmanyratsarenecessarytofindthepoisonedbottleinonehour
/* ZoomBA : Recursive */
A = ['a':'z'].string
$count = 0
def decode( string , result ){
if ( (len = #string) == 0 ) {
$count += 1 ; println( result )
return
}
if ( (inx = int(string.0) ) == 0 ) return
// now the rest
decode ( string[1:1] , result + A[inx  1] )
if ( len > 1 ){
two = string[0:1] ; inx = int(two)
if ( inx < 27 ){
decode ( string[2:1] , result + A[inx  1] )
}
}
}
ip = '1123'
decode(ip,'')

NoOne
November 01, 2016 // ZoomBA : Bad, elementary, declarative.
LL = [ [4, 10, 15, 24, 26] ,
[0, 9, 12, 20] ,
[5, 18, 22, 30] ]
range = reduce( LL ) > {
min = $.prev[0] ; max = $.prev[1]
if ( min > $.item[0] ){ min = $.item[0] }
if ( max < $.item[1] ){ max = $.item[1] }
[ min, max ]
}
r = [range.0 : range.1 + 1]
join ( r, r ) :: {
#(min,max) = $.o // tuple
continue ( min > max )
out_of_range = exists ( LL ) :: {
!exists( $.item ) :: { min <= $.item && $.item <= max }
}
continue ( out_of_range  ( max  min > range.1  range.0 ) )
range.0 = min ; range.1 = max
false
}
println( range )

NoOne
November 01, 2016 // ZoomBA uLanguage. Simple.
paths = [ '', '' ]
def find_paths( key1, key2, node , path ){
if ( !empty(path.0) && !empty(path.1) ) return
if ( node == null ) {
if ( path #$ key1 ){ paths.0 = path }
if ( path #$ key2 ){ paths.1 = path }
return
}
find_paths ( node.left, path + '/' + node.key )
find_paths ( node.right, path + '/' + node.key )
}
// find paths
find_paths( key1, key2, root, '' )
// split and now match
paths.0 = paths.0.split('/')
paths.1 = paths.1.split('/')
#(s,l) = minmax ( paths ) :: { #$.left < #$.right }
inx = index ( [ #s1:1 ] ) :: {
paths[0][$.item] != paths[1][$.item]
}
println( s[0][inx] )

NoOne
October 30, 2016 // ZoomBA
def conforms( demand, supply ){
// write code here
// this is a predicate filter
// should it subtract too? No idea
demand.quantity <= supply.quantity &&
time ( supply.expirationDate )  "P3D" > demand.expirationDate
// note the use of en.wikipedia.org/wiki/ISO_8601#Durations
}
// this template code, does not need to change
dict ( demands ) > {
demand = $.item
// read : select all supplies such that they conform to the demand
conformed_supplies = select ( supplies ) :: { conforms ( demand , $.item ) }
[ demand , conformed_supplies ]
}
// this is how business should code it. ALAS.

NoOne
October 30, 2016 // ZoomBA
paren_arr = [ { _'<' : 1 , _'>' : 1 , 'c' : 0 },
{ _'(' : 1 , _')' : 1 , 'c' : 0 },
{ _'{' : 1 , _'}' : 1 , 'c' : 0 },
{ _'[' : 1 , _']' : 1 , 'c' : 0 } ]
// now the indexing
parens = { _'<' : 0 , _'>' : 0 ,
_'(' : 1 , _')' : 1 ,
_'{' : 2 , _'}' : 2 ,
_'[' : 3 , _']' : 3 }
def match_paren(string){
fold ( string.value , true ) > {
matcher = paren_arr[ parens[ $.item ] ]
matcher.c += matcher[ $.item ]
break ( matcher.c < 0 ){ false }
true
} && ! ( exists ( paren_arr ) :: { $.item.c != 0 } )
}
println ( match_paren ( "<({()})[]>" ) )
println ( match_paren ( "<({([)})[]>" ) )
This is fully declarative. The logic is actually implemented in the maps, while the engine simply runs it through, also fully extensible.
 NoOne October 30, 2016Sergey is right. Just adding another interesting mix :
/*
With extra space, again exact in 2n
Given array not sorted
*/
def single_pass( arr , S ){
s = set( arr ) // create a set out of it
// find item x in arr such that S x is in the set!
v = find ( arr ) :: { (S  $.item) @ s }
v.nil ? 'Nothing' : v.value
}

NoOne
October 30, 2016 // ZoomBA
// Tree Node schema
def t_node : { v : 0 , l : left_node , r : right_node }
paths = list()
def find_paths( node , path ){
if ( empty(node) ){
paths.add ( path.split('/') )
return
}
if ( !empty( node.left ) ){
find_paths ( node.left , path + '/' + node.left.v )
}
if ( !empty( node.right ) ){
find_paths ( node.right , path + '/' + node.right.v )
}
}
// call this way
find_paths ( root, '/' + root.v )

NoOne
October 30, 2016 // ZoomBA
/*
A replacement of '*' > '(' implies +1
A replacement of '*' > ')' implies 1
At any point, if the count is < 0, drop the path.
Finally, if the count is == 0, accept the path.
As we have three options, the choices can be made in ternary,
Thus, given k choice locations, there are 3 ** k options
Hence, we can reduce the recursion to iteration.
Using a mixture of imp/dec because of readability
*/
def count_options( s ){
num_stars = sum( s.value ) > { $.item == _'*' ? 1 : 0 }
options = set() ; len = #s
map = { _'0' : '', _'1' : '(' , _'2' : ')' , _'(' : 1, _')' : 1 }
for ( select_pattern : [0: 3 ** num_stars ] ){
star_count = 1
ter_pattern = str( select_pattern , 3 )
ter_pattern = '0' ** ( #ter_pattern   num_stars ) + ter_pattern
transformed = fold( s.value ,'' ) > {
$.prev + ( $.item == _'*' ? map[ter_pattern[ star_count += 1 ]] : $.item )
}
continue( transformed @ options ) // avoid unnecessary stuff
res = sum ( transformed.value ) > {
break( $.prev < 0 ){ len } ; map[$.item]
}
if ( res == 0 ){ options += transformed }
}
println( str( options,'\n' ) )
size( options ) // return size of options
}
println( count_options( '(*(*)*)' ) )

NoOne
October 29, 2016 // ZoomBA
def sales_force( s ){
len = #s
if ( len == 0 ) return ''
#(last,cnt, ret) = fold ( [1:len] , [s[0], 1, '' ] ) > {
#(prev, count, res ) = $.prev
if ( prev != s[$.item] ){
res += ( str( prev ) + count )
count = 1
}else{
count +=1
}
[ s[$.item] , count , res ]
}
ret += ( str( last ) + cnt )
}
s = 'aaabbdcccccf'
println( sales_force( s ) )

NoOne
October 29, 2016 // ZoomBA avoids coding... thus :
def do_fb( l ){
sorta ( l ) :: { $.left.0 < $.right.0 }
// merge and sum intervals
#(s,last) = fold ( [1:#l] , [ 0 , l[0] ] ) > {
prev = $.prev[1] ; cur = l[$.item]
if ( prev.1 >= cur.0 ){ // there is overlap
// but, is current fully inside previous?
if ( prev.1 < cur.1 ){
// merge them
$.prev[1] = [ prev.0 , cur.1 ]
}
} else {
// update sum
$.prev.0 += ( prev.1  prev.0 )
$.prev.1 = cur
}
$.prev
}
s += ( last.1  last.0 )
}
input = [[1,4], [6,8], [2,4], [7,9], [10, 15]]
println ( do_fb( input ) )

NoOne
October 29, 2016 // ZoomBA
def first_non_repeat(string){
// use sorted dictionary to keep insertion order
d = fold ( string.value , sdict() ) >{
if ( $.item @ $.partial ){ $.partial[ $.item] += 1
} else { $.partial[ $.item] = 1 }
$.partial
} // this is now an multi set : search for first entry with count 1
r = find ( d ) :: { $.item.value == 1 }
// Option Monad, either exists or does not
println ( r.nil ? 'Nothing' : r.value.key )
}
first_non_repeat ( "aaaabbbbacccdbbbbeeeg" )

NoOne
October 28, 2016 As our previous code was grossly complex, this one does crack the algo fine. nJoy, ZoomBA
/*
1. Start with the substring from start which is anagram of a word
2. Now match recursively the rest
3. Test if everyone can generate a non empty word list or not
Doing it recursively, push to stack if need be : string, words_until_now
*/
def do_googles_bidding( string , sorted_dict , words_until_now ){
for ( end : [0:#string] ){ // making it non trivial
s = string[0:end] // splice
sorta( s.value ) // sort and gen key
if ( s @ sorted_dict ){
if ( end == #string  1 ){ // in this case, we have found a match
// note : I am not translating back the actual words, that is trivial
println ( words_until_now + ',' + s ) ; return }
// now, do on the suffix string
do_googles_bidding( string[end+1:1] , sorted_dict , words_until_now + ',' + s )
}
}
}
// generate the sorted dict
sorted_dict = mset ( file( '/usr/share/dict/words' ) ) > {
lc = $.o.toLowerCase() ; sorta( lc.value ) ; lc }
do_googles_bidding( 'elhloothtedrowl' , sorted_dict , '')

NoOne
October 26, 2016 // ZoomBA : Imperative solution, because people may not like the declarative one
/*
Two phases to do it.
1. Generate all possible splitting  partition of the input string
2. Given a partition, sort the individual words in the split
3. Check if all the words belongs to the dictionary by matching them
4. Against a pre word sorted dictionary
*/
def do_googles_bidding( string , sorted_dict ){
len = #string
for ( n : [ 0 : 2 ** (len  1)] ){
sn = str(n,2)
sn = '0' ** ( len  #sn ) + sn // 0 padded
end = len  1 ; start = end
partitions = list()
failed = false
while ( start >= 0 ){
if ( sn[start] == _'1' ){
p = string[start:end]
// generate the key by sorting chars, and checking
lc = p.toCharArray() ; sorta(lc) ; lc = str(lc,'')
break ( !(lc @ sorted_dict) ) { failed = true }
partitions.add(0, lc ) // add the sorted key
end = start  1
}
start = 1
}
if ( !failed && end >= 0 ){
p = string[0:end]
lc = p.toCharArray() ; sorta(lc) ; lc = str(lc,'')
if ( lc @ sorted_dict ) {
partitions.add(0, lc )
println( partitions )
return partitions
}
}
}
return []
}
// generate the sorted dict
sorted_dict = mset ( read( '/usr/share/dict/words' ) ) > {
lc = $.o.toLowerCase() ; sorta( lc.value ) ; lc }
result = do_googles_bidding( 'elhloothtedrowl' , sorted_dict )
println ( result )

NoOne
October 26, 2016 // ZoomBA
def max_palindrome( string ){
// create a mapping of char > count
cb = mset ( string.value )
#(m,M) = minmax( cb ) :: {
#(l,r) = $.item ; (2 /? l.value)  (l.value < r.value) }
middle = (2 /? M.value) ? '' : str( M.key )
// generate palindrome by appending v to left and right
fold ( cb , middle ) > {
// no need to take care of even n odd because, (2x+1)/2 > x anyways
v = str( $.item.key ) ** ($.item.value /2 )
v + $.partial + v
}
}
s = 'akjhadajsoadjaoiwjewaodjaosid'
println ( max_palindrome( s ) )

NoOne
October 22, 2016 /*
Binary Tree :
a
/ \
/ right_tree
/
left_tree
*/
tree_pre = "(a (left_tree)(right_tree))"
tree_in = "((left_tree) a (right_tree))"
tree_post = "((left_tree) (right_tree) a)"
/* use () to define non existing node */
Any of them would simply work out well. This is a very simple form, isomorphic to a JSON encoding of the same as map of maps.
 NoOne October 22, 2016// ZoomBA
def group( s, k ){
s = s.replace('','')
len = #s
rreduce ( s.value ) > {
(( $.index != 0 && k /? ( len  $.index) )?'':'') +
$.item + $.prev }
}
s = "24a0r74k"
println ( group ( s, 2 ) )
println ( group ( s, 3 ) )
println ( group ( s, 4 ) )
println ( group ( s, 5 ) )

NoOne
October 21, 2016 /* ZoomBA
1. When both strings have same length
> Check if they differ in only one char
2. When both strings differ in length
> Check if they differ only by 1 size
> larger can be created by a split of the smaller:
> larger = smaller_1 new_char smaller_2
*/
def same_length(string1, string2){
counter = 0
!exists ( [0: #string1 ] ) :: {
counter += ( ( string1[$.o] != string2[$.o] ) ? 1 : 0 )
counter > 1 // updates local, seeded by global
}
}
def diff_length( smaller , larger ){
first_diff = index ( [0:#smaller] ) :: {
smaller[$.o] != larger[$.o] }
// from first diff, everything else should match
!exists ( [first_diff : #smaller ] ) :: {
smaller[$.o] != larger[$.o + 1 ] }
}
def one_distant_apart( s1, s2 ){
l1 = #s1 ; l2 = #s2
if ( #l1 l2  > 1 ) return false
if ( l1 == l2 ) { return same_length( s1, s2 ) }
if ( l1 < l2 ){ return diff_length ( s1, s2 ) }
return diff_length ( s2, s1 )
}

NoOne
October 20, 2016 // ZoomBA : Much better optimised code.
board = [ [ 'h', 'i', 'c', 'f'],
[ 'g', 's', 'b', 'k'],
[ 't', 'z', 't', 'v'],
[ 'n', 'e', 'd', 'u'] ]
map = fold ( board , dict() ) > {
row = $.item ; row_index = $.index
$.partial = dict( row ) > {
[ board[row_index][$.index] , [ row_index , $.index ] ] }
}
def is_found( positions ){
fold ( [1: #positions ] , [ true, true, true ] ) :: {
#(p_r, p_c) = positions[ $.item  1]
#(r, c) = positions[ $.item ]
#(h,v,d) = $.partial
// horizontal
h &= ( (p_r == r ) && ( c  p_c == 1 ) )
// vertical
v &= ( ( r  p_r == 1 ) && ( c == p_c ) )
// diagonal
d &= ( ( r  p_r == 1 ) && ( c  p_c == 1 ) )
[ h, v, d]
}
}
def word_exists( word ){
if ( empty(word) ) return false
#(positions ? e ) = list ( word.value ) > { map[str($.item)] }
if ( empty(positions) ) return false
#(h,v,d) = is_found( positions )
( h  v  d )
}
println( word_exists ( 'hi') )
println( word_exists ( 'is') )

NoOne
October 20, 2016 You are almost right Chris brackets matching are not regular.
They are (Non deterministic) Context Free at best.
And yea I give n take interviews fairly regularly.
Appeared for : 50+ , Taken : 600+. There were days where I used to take 10 interviews a day, and there are days where I used to appear for 3 full panel interview a day. It is a fun activity.
// ZoomBA
def term_parse( s ){
term = [ 0.0 , '' ]
p = tokens('^[\+\]?(\d+(\.\d+)?)?')
m = p.matcher( s ) ; m.find() // true always
opts = { '' : 1.0 , '+' : 1.0 , '' : 1.0 }
if ( m.group @ opts ) {
term[0] = opts[ m.group ]
} else {
term[0] = float( m.group )
}
inx = index ( s.value ) :: { str($.item) =~ '[azAZ]' }
term[1] = s[ (inx < 0 ? 0 : inx) : 1 ]
if ( inx < 0 ){ term[1] = '' }
term
}
def gen_expr( s ){
l = tokens(s, '[\+\]?[^\+\]+') > { term_parse( $.item ) }
d = mset ( l ) > { $.item.1 }
}
def normalize( s ){
s = s.replace(' ','')
#(l,r) = s.split('=')
ld = gen_expr ( l )
rd = gen_expr ( r )
// merge
u = ld.keys  rd.keys // union
poly = list ( u ) > {
k = $.item ; coeff = 0.0
if ( k @ ld ){ coeff += sum ( ld[k] )>{ $.item[0] } }
if ( k @ rd ){ coeff = sum ( rd[k] )>{ $.item[0] } }
[ k , coeff ]
}
sortd ( poly ) :: { #(l,r) = $.item ; l.0 < r.0 }
str( poly , '' ) > { #(k,c) = $.item ; str( '%+f%s' , c , k ) }
}
x = normalize ( 'x^2 + 3.5xy + y = y^2  xy + y + 10' )
println ( x )

NoOne
October 19, 2016 Very imprecise formulation. Given the problem is :
1. False positives are not allowed : > Do not say found, when it is not actually there.
2. False negatives are allowed > Can say not found, when it is there.
These two axioms trivialises the problem. Just store the portion of the list as set what is possible in the memory.
Say "yes" when it exists in the set, otherwise say "No".
Was it a trick question?
// ZoomBA : Better optimised code
def is_palindrome( s, i, j ){
!exists ( [i : (j  i)/2 + i + 1 ] ) :: {
s[ $.item ] != s[ i + j  $.item ]
}
}
def find_max_palindrome( string ){
max_palindrome = [0,0] ; r = [0:#string]
join ( r, r ) :: {
i = $.item.0 ; j = $.item.1
continue( max_palindrome.1  max_palindrome.0 > j  i 
!is_palindrome( string , i, j ) )
max_palindrome.0 = i ; max_palindrome.1 = j
false
}
string[ max_palindrome.0 : max_palindrome.1 ]
}
s = "DEFABCBAYT"
r = find_max_palindrome( s )
println(r)

NoOne
October 18, 2016 From the same Java Code. My first code is a sham, and should be avoided.
This, on the other hand is very concise. Abhinav, note that 11 mapping with ZoomBA land and Java island are possible, see code in both the languages :
def path_2_root( emp, tree ){
path = ''
while ( emp @ tree ){
path += ( emp + '\t' )
emp = tree[emp]
}
path += emp
return path.split('\t')
}
def do_ibm( s ){
values = s.split(",")
tree = dict ( [0: size(values)  2 ] ) > {
pair = values[ $.item ].split('>')
[ pair[1] , pair[0] ]
}
emp1 = values[2]
emp2 = values[1]
path1 = path_2_root( emp1 , tree )
path2 = path_2_root( emp2 , tree )
len = size( path1 ) > size( path2 ) ? size( path1 ) : size( path2 )
resolver = fold( [1:len] , '' ) > {
break ( path1[  $.item ] != path2[  $.item ] )
$.prev = path1[  $.item ]
}
}

NoOne
October 18, 2016 import java.util.HashMap;
import java.util.Map;
/**
* Created by NoOne on 18/10/16.
*/
public class Main {
static String s = "Frank>Mary,Mary>Sam,Mary>Bob,Sam>Katie,Sam>Pete,Bob>John,Bob,Katie" ;
static Map<String,String> createDict(String[] items){
Map<String,String> m = new HashMap();
for ( int i = 0 ; i < items.length  2 ; i++ ){
String[] pair = items[i].split(">");
m.put( pair[1], pair[0] );
}
return m;
}
static String[] pathToRoot( String employee, Map<String,String> tree){
StringBuffer buf = new StringBuffer();
while ( tree.containsKey( employee ) ){
buf.append( employee ).append( "\t") ;
employee = tree.get( employee );
}
buf.append( employee );
return buf.toString().split( "\t" );
}
static void doIBM( String s ){
String[] values = s.split(",");
Map<String,String> tree = createDict( values );
String emp1 = values[ values.length 2 ] ;
String emp2 = values[ values.length 1 ] ;
String[] path1 = pathToRoot( emp1 , tree ) ;
String[] path2 = pathToRoot( emp2 , tree ) ;
int len = path1.length > path2.length ? path1.length : path2.length ;
String resolver = "" ;
for ( int i = 0; i < len ; i++ ){
if ( !path1[ path1.length  1  i ].equals( path2[ path2.length 1  i] ) ) {
break;
}
resolver = path1[ path1.length  1  i ];
}
System.out.println(resolver);
}
public static void main(String[] args){
doIBM(s);
}
}

NoOne
October 18, 2016 Due to peoples request. Guys, I think it is good to learn pseudocoding on functional style.
Then, you can apply that to get faster, better imperative coding. NOTE: Java is not a very decent language for learning coding, python is much better.
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Created by NoOne on 17/10/16.
*/
public class Main {
static String[] s = new String[] { "IBM cognitive computing" , "IBM \"cognitive\" computing is a revolution" ,
"ibm cognitive computing" , "'IBM Cognitive Computing' is a revolution?" };
static List<String> tokenize(String text, String regex){
Pattern p = Pattern.compile( regex , Pattern.DOTALL);
Matcher m = p.matcher( text );
List<String> l = new ArrayList<>();
while ( m.find() ){
l.add(m.group());
}
return l;
}
static String keyString( List l, String sep){
StringBuffer buf = new StringBuffer();
for ( Object o : l ){
buf.append( o ).append(sep);
}
String s = buf.toString();
return s.substring(0,s.length());
}
static void doIBM( String[] s ){
String previousKey = "" ;
String previousValue = "" ;
for ( String item : s ){
List words = tokenize( item.toLowerCase() , "[az09]+");
String key = keyString( words , " " );
if ( key.indexOf( previousKey ) < 0 
( previousKey.equals(key) && item.length() > previousValue.length() ) ){
continue;
}
previousKey = key ;
previousValue = item ;
}
System.out.println(previousValue);
}
public static void main(String[] args){
doIBM(s);
}
}

NoOne
October 17, 2016 Imagining this as the longest path problem :
// to store all the paths x/y/z form
ALL_PATHS = list()
// how to enumerate all root to leaf
def enumerate_paths( node , path ){
if ( empty(node.children) ) {
// add the path, because node is leaf
ALL_PATHS += path
return // nothing more is to be done
}
for ( c : node.children ){
// recurse into it
enumerate_paths ( c , path +'/' + c.id )
}
}
// enumerate all the paths
enumerate_paths ( root, '' )
/* all these paths are from root to leaf,
so find a pair such that :
1. The overlap is only at root
2. And is max length */
len = #ALL_PATHS
max = [ '' , '' , 0 ]
for ( i : [0:len] ){
for ( j : [i + 1 : len] ){
p1 = ALL_PATHS[i] ; p2 = ALL_PATHS[j]
a = p1.split('/') ; b = p2.split('/')
total_len = size(a) + size(b)
// a.0 == b.0 means overlap, e.g. /x/y , /x/z
if ( a[0] != b[0] && total_len > max.2 ){
max.0 = p1 ; max.1 = p2 ; max.2 = total_len
}
}
}
// here we have everything
println ( max )
// and note that we are still less than 42 lines

NoOne
October 17, 2016 The basic is trivial. Here is how to solve it.
// ZoomBA
ip1 = "Frank>Mary,Mary>Sam,Mary>Bob,Sam>Katie,Sam>Pete,Bob>John,Bob,Katie"
ip = "Sam>Pete,Pete>Nancy,Sam>Katie,Mary>Bob,Frank>Mary,Mary>Sam,Bob>John,Sam,John"
values = ip.split(",")
mgr = dict( [0: #values  2 ] ) >{
#(k,v) = values[$.item].split('>') // mgr : employee
if ( k @ $.partial ){
$.partial[k] += v
}else{
$.partial[k] = list(v)
}
[k, $.partial[k] ]
}
emp = [ values[2] , values[1] ]
//root, the employee who never comes as value as managed
rs = mgr.keys  fold ( mgr.values , list() ) > { $.partial += $.item }
assert ( size(rs) == 1 ,'How come multiple Organizations?' )
root = for ( rs ){ $ } // idiomatic extraction of root
def get_path (emp, node, path ){
if ( emp == node ) return path
if ( !(node @ mgr) ) return ''
for ( c : mgr[node] ){
r = get_path ( emp, c, path + '/' + c )
if ( !empty(r) ) return r
}
return ''
}
// now find paths and compare :: because every time tree changes
x = get_path (emp.0, root, root )
println(x)
y = get_path (emp.1, root, root )
println(y)
x = x.split('/') ; y = y.split('/')
#(n,M) = minmax( #x , #y )
i = index ( [0:n] ) :: { x[ $.item ] != y[ $.item ] }
println ( x[i1] )

NoOne
October 17, 2016 // ZoomBA
// preprocessing :: generate the n X n grid
n = 8
// create grid
grid = list ( [0:n] ) > { list( [0:n] ) > { 0 } }
// basic function to put the lamp
def put_lamp( x, y ){
fold ( [0:n] ) > { grid[ x ][ $.item ] = 1 }
fold ( [0:n] ) > { grid[ $.item ][ y ] = 1 }
// left top > bottom right diagonal
i = x ; j = y
while ( i >= 0 && j >= 0 ) { grid[i][j] = 1 ; i =1 ; j=1 ; }
i = x ; j = y
while ( i < n && j < n ) { grid[i][j] = 1 ; i +=1 ; j+=1 ; }
// top right > bottom left
i = x ; j = y
while ( i >= 0 && j < n ) { grid[i][j] = 1 ; i =1 ; j+=1 ; }
i = x ; j = y
while ( i < n && j >= 0 ) { grid[i][j] = 1 ; i +=1 ; j=1 ; }
}
put_lamp ( 5, 1 )
// print the grid
fold ( grid ) > { printf('%s\n' , str( $.item , ' ' ) ) }

NoOne
October 16, 2016 Non trivial code. Absolutely non trivial. Here is one part of it, when the dates are larger than 1970 Jan 01 :
MS_IN_NORMAL_YEAR = 365 * 24* 60 * 60 * 1000
MS_IN_LEAP_YEAR = 366 * 24 * 60 * 60 * 1000
DAYS_IN_MONTH = [ 0, 31, 28 , 31, 30, 31, 30, 31, 31, 30, 31 , 30, 31 ]
def is_leap_year( year ){
return ( ( 400 /? year )  ( !( 100 /? year ) && ( 4 /? year ) ) )
}
def get_ms_in_month( month, is_leap ){
if ( is_leap && month == 2 ) return 29 * 24 * 60 * 60 * 1000
return DAYS_IN_MONTH[month] * 24 * 60 * 60 * 1000
}
def date( millisec ){
year = 1970 // *nix inception year
is_leap = is_leap_year( year )
ms_in_year = ( is_leap ? MS_IN_LEAP_YEAR : MS_IN_NORMAL_YEAR )
while ( millisec > ms_in_year ){
millisec = ms_in_year
year +=1
is_leap = is_leap_year( year )
ms_in_year = ( is_leap ? MS_IN_LEAP_YEAR : MS_IN_NORMAL_YEAR )
}
println ( year )
// at this point, we have found the years, now add months
month = 1
ms_in_month = get_ms_in_month ( month, is_leap )
while ( millisec > ms_in_month ){
millisec = ms_in_month
month +=1
ms_in_month = get_ms_in_month ( month, is_leap )
}
days = (millisec / ( 24 * 60 * 60 * 1000 )) + 1
[ days, month, year ]
}
res = date ( 1476615214741 )
println( res )

NoOne
October 16, 2016 Dumbo Strategy. Not smart but does the job.
Suppose the graph has K pair of nodes, which are not connected.
We are not considering en.wikipedia.org/wiki/Multigraph.
In that case we need to add to these pairs all pairs having edge length more than 2.
Now, the problem becomes :
find_min ( start, end, [ original , modified_1, modified_2, ...modified_k ] )
That is, finding individual shortest path in the original graph, and then modifying the graph by joining the first pair and then continuing the same.
This surely solves the problem.
But let's take a look around this a bit more.
Suppose we do this :
find_min ( start, end, [ original_graph ] )
and find the path P.
Now, if we go through the path verices by vertices, edge by edge,
can we not calculate if replacing 3 of the verices by a 2 ( by inserting the virtual edge )
reduces the min value or not?
Thus, we may solve the problem by :
1. Finding min path
2. Check if directly connecting start to end solves it or not? If not, then proceed to [2]
3. For each 3 verices in 2 edges, we check if adding a virtual edge reduces the min or not.
4. Continue storing the previous min and go to [3].
Proof Of Correctness: NONE.
As of now, this can go wrong drastically.
1. Have a credit card cache, partitioned into good and fraud.
2. When a card belong to any of the above, then do due diligence.
3. When a card belongs to neither, call the website and get the latest fraud card list.
4. Update the card cache, move from good to fraud.
5. Now, if the card is still in neither, then add the card to the good card cache.
Issue : with [2]. But it can never be fixed, really.
s = [ "IBM cognitive computing" , 'IBM "cognitive" computing is a revolution' ,
"ibm cognitive computing" , "'IBM Cognitive Computing' is a revolution?" ]
// shows the power of full declarative framework
#(full,final) = fold ( s , [ '' , '' ] ) > {
// token splitting of the current statement, basing the rules
words = tokens( $.item.toLowerCase , '[az09]+')
key = str( words , ' ' ) // preserve single whitespace if need be
previous_key = $.previous.0 // the fold structure
previous_value = $.previous.1 // unwinding
continue ( !(previous_key @ key) 
( previous_key == key && #$.item > #previous_value ) )
// when the continue did not happen, return the current as the latest
[ key, $.item ]
}
println( final )
Explanation. We note that the statements can be mapped to a key.
A key that is to be used for comparison. Obviously, if key1 is contains in key2, we need to pick key2. That is inscribed in the code.
// ZoomBA
mapping = dict()
// the basic mapping is created using this
def traverse( node , cur_x, cur_y ){
if ( !(cur_x @ mapping) ){ mapping[cur_x] = list() }
// append :store both y co ordinate as well as value
mapping[cur_x].add ( [ cur_y , node.value ])
// change the x to left, so one minus, and level one down
if ( !empty( node.left) ) { traverse( node.left, cur_x  1, cur_y + 1 ) }
// change the x to right, so one plus, and level one down
if ( !empty( node.right) ) { traverse( node.right, cur_x + 1, cur_y + 1 ) }
}
traverse( root, 0, 0 ) // basis
// sort the keys based on x coordinate
keys = sorta ( list ( mapping.keySet ) )
fold ( keys ) >{
values = mapping[$.item] // get the pair values in that key
// sort the values based on the pairs left item, e.g. y coordinate
sorta( values ) :: { $.item[0][0] < $.item[1][0] }
// now, simply print all the values : the right value
printf ( '%s', str( values , ' ') >{ $.item[1] } )
}
// end with a newline
println()

NoOne
October 14, 2016 // ZoomBA
def left_right( a ){
len = #a
odd = !(2 /? len)
left_heap = fold( a , heap( len/2 + 1 ) ) > { $.partial += $.item }
#(l,r) = fold( a, [list(),list()] ) > {
if ( $.item < left_heap.max ){ $.partial.0 += $.item }
if ( $.item > left_heap.max ){ $.partial.1 += $.item }
if ( !odd && $.item == left_heap.max ) { $.partial.1 += $.item }
$.partial
}
println ( l + (odd ? left_heap.max : []) + r )
}
a = [ 6, 4, 5, 0, 2, 1, 11 , 1 ]
left_right(a)
a = [ 6, 4, 5, 0, 2, 1, 11 , 1, 9 ]
left_right(a)

NoOne
October 14, 2016 //ZoomBA
s = "(S (NP (NNP James)) (VP (VBZ is) (NP (NP (DT a) (NN boy)) (VP (VBG eating) (NP (NNS sausages))))))"
def simplified_solution(s){
// observe that every ')' previous to that is the word to add, so :
cur = 0
len = #s
words = list()
while ( cur < len ){
r = index ( [cur: len] ) :: { s[$.item] == ')' } + cur
break ( r >= len )
l = rindex ( [ cur:r ] ) :: { s[$.item] == ' ' } + cur
break ( l >= len )
w = s[l+1:r1]
if ( !empty( w.trim() ) ) { words += w }
cur = r + 1
}
println ( str ( words , ' ' ) )
}
simplified_solution( s )
A much faster and alternative  to do it directly from string rep.
 NoOne October 13, 2016// ZoomBA
tree = { "NP" : [ { "DT" : "a" } , { "NN" : "boy" } ] }
def traverse( node , s ){
names = list( node.keySet )
name = names.0 // yes, we did it ourselves
value = node[name]
if ( value isa [ ] ){
for ( child : value ){
traverse ( child , s )
}
}else{
s += value
}
}
s = list()
traverse ( tree, s )
println( str(s, ' ') )
Here, we are forced to use minimal dictionary ( json ) format to store the parse tree.
Observe that the ordering does not matter at all for the nodes, because of the format chosen. Order is implicit in the list.
// ZoomBA
// whole string
def reverse( string , si, ei ){
fold( [ si : (si + ei + 1)/2 ] ) >{
t = string.value[ $.item ]
string.value[ $.item ] = string.value[ ei  $.index ]
string.value[ ei  $.index ] = t
}
}
// If you want to reverse the words,
def reverse_words( string ){
reverse( string , 0, #string  1 )
si = 0 ; ei = 0
len = #string
while ( true ){
while ( si < len && string[si] ==' ' ) { si += 1 }
break ( si >= len )
ei = si
while ( ei < len && string[ei] !=' ' ) { ei += 1 }
break ( ei >= len ){ reverse( string, si, len1 )}
reverse( string, si, ei  1 )
si = ei
}
}

NoOne
October 13, 2016 // ZoomBA
node = { 'id' : 0 , 'children' : list() }
visited_nodes = set()
def post_order(node){
// awesomeness of ZoomBA is linear error handling mechanism
// if condition is true, panic is raised with the message
panic ( node.id @ visited_nodes , 'I have visited this node before!' )
visited_nodes += node.id // appends it
for ( child : node.children ){
post_order( child )
}
println ( node ) // visits it
}

NoOne
October 13, 2016 1. Make a graph, from your string[] bank.
All strings become nodes.
A node is connected to another if they have a single edit distance, that is ,
a single mutation can transform one string to another. Thus, making the graph is hard affair.
Linear solution on the strings lengths exists, see below ZoomBA code.
2. Once that graph building is done, search for the node.
Keep a hashmap/trie whatever you want.
Get the start and end node. Now, apply any standard path finding mechanism to
reach from start to the end node, in the shortest path. The weight of the path is the mutation distance.
// ZoomBA
def is_edit_distance_1( string1, string2 ){
n1 = #string1 ; n2 = #string2
if ( #n1  n2 > 1 ) return false
if ( n1 == n2 ) return test_same_length( string1, string2 )
if ( n1 > n2 ) return test_one_more ( string1 , string2 )
return test_one_more ( string2 , string2 )
}
def test_same_length( string1, string2 ){
n = #string2
( lfold ( [0:n] , 0 ) >{
$.partial += (string1[$.o] == string2[$.o] ? 0 : 1 )
break ( $.partial > 1 )
$.partial
} ) == 1
}
def test_one_more( large, small ){
n = #small
first_diff = index( [0:n] ) :: {
small[ $.o ] != large[ $.o ]
}
if ( first_diff < 0 ) return true
// match the suffixes
! exists ( [ first_diff : n ] ) :: {
large[$.o+1] != small[$.o]
}
}

NoOne
October 12, 2016 // ZoomBA
def classify( string ){
// please do some menial work and list all consonants, to ensure that
// we do not false miss stuff not in [az]
// =~ is the matches operator
if ( string =~ '.*[^aeiou]{5,}.*.*[aeiou]{3,}.*' ) return 'bad'
if ( string =~ '.*[\?aeiou]{3,}.*.*(\?[^aeiou]){5,}.*' ) return 'mixed'
return 'good'
}
This is very lazy, using regex, and bad matching on them. But generally gives you the idea.
The fall back *order* is essential.
Open Chat in New Window
The solution is here, rather, inverted.
 NoOne November 02, 2016geeksforgeeks.org/searchinrowwiseandcolumnwisesortedmatrix/