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
1d
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...
Top Accenture Data Engineering Intern interview questions & answers
Popular interview questions of Data Engineering Intern
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app