Extract Characters at Prime Indices
Given a string 'STR' of length 'N', return a new string containing all characters that are located at prime indices in the original string. Ensure that the order of characters in the new string is the same as their order in the original string.
Example:
Input:
STR = "abcdefg"
Output:
"bdf"
Explanation:
Characters at prime indices 2, 3, and 5 are 'b', 'd', and 'f', respectively.
Constraints:
- The first character of the string is at index 0 (0-based indexing).
- Prime indices are those indices that are prime numbers. For example, if a character is at index 5, it is at a prime index because 5 is a prime number.
- The string contains characters from 'a'-'z', 'A'-'Z', and '0'-'9'.

AnswerBot
4mo
The task is to extract characters at prime indices from a given string and return them in the same order.
Iterate through the string and check if the index is prime.
Use a helper function to determine i...read more
Help your peers!
Add answer anonymously...
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

