Ebay Interview Question for Software Engineer / Developers
- 0of 0 votes
AnswerGiven a Hash -
my %hash = ( ABC => [123,456,789], PQR => 345, XYZ => 567, LMN => { abc => 0, pqr => 1, lmn => 2, xyz => { A => 0, B => 1, c => [ {1 => 'ONE', 2 => 'TWO',}, {ONE => 1, TWO => 2,}, {Number => 'Decimals'}, {Words => 'Alphas'}, 'Abhishek' ] } }, OPQ => 'WORD' );
Write a generic function to find value of key input by user.
- Abhishek May 17, 2010
e.g. In above example if key input by user is 'Words' then value found by search function should be 'Alphas'
Write Search($hashRef,$key) function where, hash could be of any type/level such as -
Hash of Hash of Hash of Hash
Hash of Array of Hash.
etc. etc.
use following code to return boolean value based on match
return my_hash.contains(strEnteredVal);| Report Duplicate | Flag | PURGE
Ebay Software Engineer / Developer
keep looking up nested hashes till u hit the bottom. weird Q.
- Anonymous February 26, 2014