Skip to content
Discussion options

You must be logged in to vote

We need to permute a given string such that all consonants remain in their original positions, and the vowels are sorted in non-decreasing order of their ASCII values. The vowels include both lowercase and uppercase letters 'a', 'e', 'i', 'o', and 'u'.

Approach

  1. Identify Vowels: First, we iterate through the input string to collect all vowels (both lowercase and uppercase) into an array.
  2. Sort Vowels: The collected vowels are then sorted based on their ASCII values. This ensures that the vowels are in non-decreasing order as required.
  3. Construct Result String: We then iterate through the original string again. For each character, if it is a consonant, we leave it as is. If it is a vowel, we…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@topugit
Comment options

topugit Sep 11, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Sep 11, 2025
Maintainer Author

Answer selected by topugit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants