Persistent Coding Questions and Answer in 2022
Problem
Statement :
Flipkart has been infected
with a virus, the virus works this way: Each user that has been infected with
the virus is traced by a special algorithm and a hint that the virus gives. The
virus leaves a hint number N.
Flipkart is able to identify
the user ID of the virus by this N number as the user ID works as a series :
Each number in the series is the sum of the last three numbers in the series.
The first three numbers in the series are 0, 0, 1 always.
Write a program to identify
the user ID infect based on N value checked from the logs of the system
Input
The input contains the N value
left by the virus and found by engineers in the logs of the system
Output
Print the userID of the infect
user.
Example
Input
11
Output
81
Example
Input
16
Output
1705
Program :
N = int(input("Enter a
Value : "))
N1, N2, N3 = 0, 0, 1
user_id = 0
N4 = 1
if N <= 0:
print("Please enter a positive
integer")
elif N == 1:
print(N1)
elif N == 2:
print(N2)
elif N == 3:
print(N3)
else:
for i in range(N-3):
N4 = N1 + N2 + N3
N1 = N2
#updating values
N2 = N3
N3 = N4
print(N4)
for execution and output so check the video :
Comments
Post a Comment