kaustubhonline15
BAN USER
Employee at None
Questions (3)
Comments (4)
Reputation -5
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
yes!
1) reverse the array.
2) reverse 0 to (k-1)th indexed part of array.
3) reverse k to (n-1)th indexed part of array.
original array 2 7 9 1 8 7 3
if we have to rotate right by 2 units. (k=2).
step 1: reverse it
3 7 8 1 9 7 2
step 2: reverse 0 to 1 st index
7 3 8 1 9 7 2
step 3: reverse 2nd to last
7 3 2 7 9 1 8
this is the required solution
Comment hidden because of low score. Click to expand.
0
of 0 vote
little modification. while pushing if the new value is LESS THAN EQUAL TO peek value then push in the min stack.
- kaustubhonline15 August 21, 2010Comment hidden because of low score. Click to expand.
-1
of 1 vote
printAllNth(Tree root, int n){
if(root==null)return;
if(n==0){
print(root.data)
return;
}
printAll(root.left, --n)
printAll(root.right, --n)
}// considering root level is 0 height.
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
forgot to add k = k%n
- kaustubhonline15 August 21, 2010