Eugen Hotaj
BAN USER
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
O(n) time:
2 pointers, one for arr A, one for arr B
while (i<n) increment whichever pointer is smaller
At n, return smaller of two pointers.
Comment hidden because of low score. Click to expand.
0
of 0 vote
If there is only one duplicate in the array we do:
add all numbers between 1 to n = x
add all numbers in the array = y
subtract y from x : x-y = z;
The duplicated value will be n-z.
Comment hidden because of low score. Click to expand.
0
of 0 vote
This is a bitset question.
Represent each lightbulb as a bit. On isOn(i) return bit(i).
On toggle(start,end) xor the range with 11111. If light-bulb was off (i.e 0) then 0^1=1. Else if lightbulb was on i.e(1) then 1^1=0. This will correctly toggle the range as long as the mask is built correctly.
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
Your code prints out complete garbage.
- Eugen Hotaj November 12, 2015Say you had 5/3. Then you get the first digit right : 1. However 5%3=2*10=20/5=4. This is clearly not correct since you would get 1.4 not 1.6 as needed.
What you should do is multiply numerator by numdigits, divide by denom, then place the "." as needed.