Given a number n. The task is to create an OTP by squaring and concatenating the odd digits of the number.
Input: 4365188 Output: 9256 Input: 123456 Output: 4163
Explanation: In the First example, the integers at odd places are 3, 5, and 8. So we have to return a 4 digit OTP by squaring the digits. The square of the above digits are 9, 25, 65 so the OTP to be returned is the first four digits 9256.
Approach: Iterate through the length of the string (number) with the starting index as 1 and taking the step as 2. Initialize an empty string and then concatenate the squares of the odd digit to that string. Finally, return the first four characters of the string as an OTP.
Below is the implementation.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Python | Program to generate one-time password (OTP)
- Exponential Squaring (Fast Modulo Multiplication)
- One Time Password (OTP) algorithm in Cryptography
- Securing Django Admin login with OTP (2 Factor Authentication)
- Check whether product of digits at even places is divisible by sum of digits at odd place of a number
- Python | Check if given string can be formed by concatenating string elements of list
- Python Program for Difference between sums of odd and even digits
- Python program to find the sum of all even and odd digits of an integer list
- MoviePy – Concatenating multiple Video Files
- How To Add Identifier Column When Concatenating Pandas dataframes?
- Concatenating CSV files using Pandas module
- Smallest odd number with even sum of digits from the given number N
- Python Program to Find the Number Occurring Odd Number of Times
- Python Program to Print Largest Even and Largest Odd Number in a List
- Python program to create a list of tuples from given list having number and its cube in each tuple
- Python program to calculate the number of digits and letters in a string
- wxPython - Create Radio Button using Create() function
- wxPython - Create Static Box using Create() method
- Python Program for Number of elements with odd factors in given range
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.