For the first question, I thought of an O(1) solution: Say n = 2 and k = 3 Now the minimum 2 digit number = 10**(n-1) = 10 remainder = 10%3 = 1 Ans = 10 + (k - remainder) = 10 + (3 - 1) = 10 + 2 = 12 Take another example: Say n = 3 and k = 6 Now the minimum 2 digit number = 10**(n-1) = 100 remainder = 100%6 = 4 Ans = 100 + (k - remainder) = 100 + (6 - 4) = 102
to find the longest sequence def longsub(a,n): Max=-1 cur=0 for i in range(1,n): if a[i-1]a[i]: if cur>Max: Max=cur cur=0 return Max a=[1,2,3,0,5,6,1,2,3] n=len(a) print(longsub(a,n))
15:52 If he is appending to the string n times, time complexity will be N^2 but if he is using StringBuilder like data structure in python only then time Complexity will be O(N)
to find n digit number divisible bt k! def divfinder(n,k): x=10**(n-1) for i in range(x,x+20): if i%k==0: print(i) break n=int(input()) k=int(input()) divfinder(n,k)
I think you forgot to mention the most important part of any combinatorial question: Whether repetition of elements is allowed or not? i.e whether an element is allowed to be picked multiple times or just once from the given set of numbers to be picked which in this case is [1,2,3....9] Say for example if we are allowed to do that, then [1,1,9] will be a possible valid 3 digit combination summing up to 11 but the other way round, it won't be a possible combination as 1 is occurring more than once. So if that is the case then we'll have a comparatively lesser number of possible combinations like [1,2,8], [1,3,7] etc where each element is unique.
yeah understand your point but i just wanted to check his Recursions and backtracking concept. If i wanted to check his coding abilities than i would have asked the same question with 3 4 variations. Also if You watch the interview again you will notice that i said that repetition is not allowed. Thank you for you feedback! Happy Coding!
@@nikhilmaurya7898 do you think that you can compute 10^n if n is let us say 25? and also the prev solution is also O(1) as we traversed only upto no. of digits we wanted . Hence it will br O(1) only
Can't I create a min n digit no which will be 1000(if n is 4) then after that i will get the mod of this no with the given k and add that mod to it wont it will give me the right answer??
For the first question, I thought of an O(1) solution:
Say n = 2 and k = 3
Now the minimum 2 digit number = 10**(n-1) = 10
remainder = 10%3 = 1
Ans = 10 + (k - remainder) = 10 + (3 - 1) = 10 + 2 = 12
Take another example:
Say n = 3 and k = 6
Now the minimum 2 digit number = 10**(n-1) = 100
remainder = 100%6 = 4
Ans = 100 + (k - remainder) = 100 + (6 - 4) = 102
Mistake in 2nd ques
I’m else portion max statement will come first
Then you can set current to 1
to find the longest sequence
def longsub(a,n):
Max=-1
cur=0
for i in range(1,n):
if a[i-1]a[i]:
if cur>Max:
Max=cur
cur=0
return Max
a=[1,2,3,0,5,6,1,2,3]
n=len(a)
print(longsub(a,n))
It’s great how confident he seemed!
15:52 If he is appending to the string n times, time complexity will be N^2 but if he is using StringBuilder like data structure in python only then time Complexity will be O(N)
the interviewer was about to give a hint and that guy interrupted in middle, pls bring more serious people from next time
U learned from it
We Can Learn a lot from this Mock Sessions... Thank you GFG💖
to find n digit number divisible bt k!
def divfinder(n,k):
x=10**(n-1)
for i in range(x,x+20):
if i%k==0:
print(i)
break
n=int(input())
k=int(input())
divfinder(n,k)
I think you forgot to mention the most important part of any combinatorial question: Whether repetition of elements is allowed or not? i.e whether an element is allowed to be picked multiple times or just once from the given set of numbers to be picked which in this case is [1,2,3....9]
Say for example if we are allowed to do that, then [1,1,9] will be a possible valid 3 digit combination summing up to 11 but the other way round, it won't be a possible combination as 1 is occurring more than once. So if that is the case then we'll have a comparatively lesser number of possible combinations like [1,2,8], [1,3,7] etc where each element is unique.
repetition wasnt allowed
yeah understand your point but i just wanted to check his Recursions and backtracking concept. If i wanted to check his coding abilities than i would have asked the same question with 3 4 variations. Also if You watch the interview again you will notice that i said that repetition is not allowed.
Thank you for you feedback!
Happy Coding!
@@dhananjaymishra4488 Fine :)
@@dhananjaymishra4488 In the first question I think we can answer it in O(1) like 10^n-(10^n)%k ,is it correct ?
@@nikhilmaurya7898 do you think that you can compute 10^n if n is let us say 25?
and also the prev solution is also O(1) as we traversed only upto no. of digits we wanted . Hence it will br O(1) only
23:03 Here current will after max() function.
Please upload mock of serious candidates.
Can't I create a min n digit no which will be 1000(if n is 4) then after that i will get the mod of this no with the given k and add that mod to it wont it will give me the right answer??
The first question was very easy....
Does drop year mean after 12 a drop year?
for the first qsn its dammm ezz
if n = 5
and k = 1234
then ans will be 12340
if n=4 then 1234
if n=69 then 12340000000....up to 69 digits
Bhakshi😭❤