sLeviN
BAN USER
Comments (3)
Reputation 0
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
@Daisy we dont need to subtract newly added number as
if S(i, j)<x and we added j+1 th element to make it,
S(i, j+1)>x, we just need to check by removing ith element,
ie check S(i+1, j+1),
we dont need to check S(i+1,j) as always S(i+1,j)<X as S(i,j)<X and ith element is positive!
P.S. S(i,j) is sum of ith to jth elements and X is the given number
Comment hidden because of low score. Click to expand.
0
of 0 vote
just use two pointers, old,new
old=A;
while(*old!=*(old+1))
old++;
new++=++old;
for(int i=0;i<size-(new-A);i++){
if(*old!=*new){
*old=*new;
old++;
}
new++;
}
while takes old to original of the1st duplicate and then new++=++old make old point to 1st duplicate and new to next element.
now we copy from new to old if new is not a duplicate.
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
Use a set and the insert the elements in reverse order
- sLeviN August 24, 2012but to find how many are smaller than it, no need for any calculation
its the position in the set.