You are here : InfyTQ Archive >> InfyTQ Coding Problems
You will be given a number in the form of string, extract out digits at odd places, square & merge them. First 4 digits will be the required OTP.
Input :
First Input : String
Output : 4 digit OTP
Sample Testcases :
I/P 1:
34567
O/P 1:
1636
Solution :
n=input()
s=””
i=0
for i in range(0,len(n)):
if int(i)%2==1:
s+=str(int(n[i])**2)
print(s[:4])
If possible please provide more tricky test cases (hidden) so that the we will increase our learning scope without limiting our capability of coding only for a sample test case.
import java.util.*;
import java.io.*;
public class OTP {
public static void main(String[] args) throws Exception{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String s=br.readLine();String s1=””;
for(int i=1;i<s.length();i=i+2){
s1+=Integer.parseInt(""+s.charAt(i))*Integer.parseInt(""+s.charAt(i));
}
System.out.println(s1.substring(0,4));
}
}
string=input()
print(”.join([str(int(x)**2) for x in string if string.index(x)%2!=0]))