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'.
Be the first one to answer
Add answer anonymously...
Accenture Data Engineering Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter