Python Program to create an OTP by squaring and concatenating the odd digits of a number
Given a number n. The task is to create an OTP by squaring and concatenating the odd digits of the number. Examples:
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.
Time Complexity: O(n)
Auxiliary Space: O(n)
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses
are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!