sunghw
BAN USER
Questions (1)
Comments (3)
Reputation 10
- 0of 0 votes
AnswersGiven an unsorted integer array, place all zeros to the end of the array without changing the sequence of non-zero elements. (i.e. [1,3,0,8,12, 0, 4, 0,7] --> [1,3,8,12,4,7,0,0,0])
- sunghw in United States| Report Duplicate | Flag | PURGE
Bloomberg LP Financial Software Developer Algorithm
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
Wait, if it's 1 2 3 0 7,
when i = 4 and end = 4, a[4] !=0, but i==end, so both i and end decrement.
i = 3, end = 3, a[3]==0, so only i decrements.
i=2, end=3, a[2] = 3, and i<end, so they swap.
12037.
I do not think it is working... There is no way you will swap the end elements 3, 7 with the zero element in the middle at this point... isn't it?
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
no, that would be easy. you can't use any additional buffer.
- sunghw March 15, 2012