## bebo

BAN USERMore often than not, they wud like to see your cpp + pointers coding skill with this question. So, try to code in cpp/c.

Possible solution:

- count no. of spaces in input ( say x)

- take new array of [strlen(input) + 2x]

- scan from back and move letters to end. If space is encountered, put it accordingly.

similar type question:

compress a string which has multiple spaces in it with single spaces.

- For this, start scanning from 0th position.

~ In both ways, you will have to copy/shift less no. of elements.

If a one to one mapping has to be shown for elements in tree and items in array, then we can XOR the elements of tree (using any traversal) [say X] and then XOR the items in array [say Y] .

if X XOR Y = 0 , then all the items in tree are present 1:1 to that in array.

If we get these n distances in a list and sort them then the first m entires will give us the required result. But since n is O(billions) , sorting wont be a good option.

Keep min heap of m-records and find the max and min of that heap. Take (m+1)th record (say x).

if( x > max ) move to (m+2)

if( x< min || (min<x<max))remove max from heap, put x in place of that, and re-heapify

When all records are finished, the records i heap is the result. or u can do a heapsort at last.

Rep**markglove17**, Associate at Arista NetworksHi, I am Mark from North Edwards, CA .I am just crazy about dance.I am not professionally trained, but ...

Rep**RussBDycus**, Android test engineer at ABC TECH SUPPORTI am working as a manager in Lionel Kiddie City company. I really enjoy my job. I like to play ...

Rep**sylviarashtons**, Accountant at ASAPInfosystemsPvtLtdI am a journalist. Outside the office, I enjoy additional writing time in a different genre of historical fiction. I ...

Rep**junehudson**, Associate at Advisory Board CompanyI am passionate about fashion and love to explore black magic to take revenge.Being a fashion designer involves more ...

Rep**kylecfarrell**, Personnel at BocadaProperty custodian with a reputed organization and help in keeping accurate check over the supplies and inventory of materials and ...

**CareerCup**is the world's biggest and best source for software engineering interview preparation. See all our resources.

Open Chat in New Window

Its like increasing slope and then decreasing slope. We have to find the highest point.

- bebo September 11, 2011That highest point cud be found out by using binary search, and check if

a[mid-1] a[mid] a[mid+1] is in increasing or decreasing order.

if increasing , move to right half

if decreasing, move to left half

Stopping criteria: a[mid-1] < a[mid] > a[mid+1]