Skip to content

Instantly share code, notes, and snippets.

@rozer007
Created October 27, 2021 07:26
Show Gist options
  • Save rozer007/bc821ae18be78a4e8a5ce382ef80c0d4 to your computer and use it in GitHub Desktop.
Save rozer007/bc821ae18be78a4e8a5ce382ef80c0d4 to your computer and use it in GitHub Desktop.
The Curious Case Of Benjamin Bulbs
Q1) Why only perfect square are on after the nth number of fluctuation ?
ans: All perfect square numbers have odd numbers of factors so it will be on after nth number of fluctuation.
Q2) Why is the condition i*i<=n ?
ans: Since we are checking only the perfect square that why we are checking the condition for square.
Q3) what will the time complexity and space complexity ?
ans: time complexity : O(logn)
Space complexity : O(1)
Hint 1: Do a dry run for 20 bulbs with 20 fluctuation and try to see the pattern .
Hint 2: Check for number with odd numbers of factor.
Hint 3: All perfect square number have odd number of factors.
Hint 4: All perfect square number will be on.
Q1) fill the blank for this problem ?
for(int i = 1; ______ ; i++)
{
System.out.println(i * i);
}
a) i<=n
b) i<n
c) i*i<n
d) i*i<=n
ans: d) i*i<=n
Q2) What is the time complexity for this code?
1. O(N)
2. O(N^2)
3. O(1)
4. O(log N)
ans: 4)
Q3) What will be the output for 23?
a) 1 4 9 16
b) 1 2 6 7
c) 1 4 9 16 24
d) 1 3 5 6 9
ans: a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment