
Concept explainers
Problem taken from LeetCode
// Problem Statement :
// You are given a string.
// Write a function that takes a string as input and reverse only the vowels of a string.
// Example :
// Sample Input - 1 :
// "hello"
// Sample Output - 1 :
// "holle"
// Sample Input - 2 :
// "leetcode"
// Sample Output - 2 :
// "leotcede"
class Solution {
public:
string reverseVowels(string s) {
int i = 0 , j = s.size() - 1;
while(i < j) {
while(i < j &&
(s[i] != 'a' &&
s[i] != 'e' &&
s[i] != 'i' &&
s[i] != 'o' &&
s[i] != 'u' &&
s[i] != 'A' &&
s[i] != 'E' &&
s[i] != 'I' &&
s[i] != 'O' &&
s[i] != 'U'
)) {
i++;
}
while(j > i &&
(s[j] != 'a' &&
s[j] != 'e' &&
s[j] != 'i' &&
s[j] != 'o' &&
s[j] != 'u' &&
s[j] != 'A' &&
s[j] != 'E' &&
s[j] != 'I' &&
s[j] != 'O' &&
s[j] != 'U'
)) {
j--;
}
if(i < j) {
swap(s[i] , s[j]);
i++;
j--;
}
}
return s;.

Step by stepSolved in 3 steps

- Create a Flowchart: # User defined function for logic OR# The function takes two parameters and returns a single intdef OR(a: int, b: int)->int: # If a is equal to 1 return 1 if a == 1 : return 1 # If b is equal to 1 return 1 elif b == 1 : return 1 # If a and b is equal to 0 return 0 else : return 0 # User defined function for logic NOR# The function takes two parameters and returns a single intdef NOR(a: int, b: int)->int: # If a is equal to 0 and b is also equal to 0 return 1 if a == 0 and b == 0 : return 1 # If a is equal to 0 and b is equal to 1 return 0 elif a == 0 and b == 1 : return 0 # If a is equal to 1 and b is also equal to 0 return 0 elif a == 1 and b == 0 : return 0 # If a is equal to 1 and b is also equal to 1 return 0 elif a == 1 and b == 1 : return 0 # User defined function for logic AND# The function takes two parameters and returns a single intdef AND(a: int, b:…arrow_forwardC++ Programmingarrow_forwardin C++ Write an inductive function, called IndFn, for adding 12+10+8+6+4 Write a function with a procedural loop, called ProFun, for adding 14+12+10+8+6+4;arrow_forward
- C++ - No library functions like atoi Write a machine language program to output your first name on the output device. Submit your "machine code" followed by a 'zz.' An example of the machine code to output "hello" is shown below. This is an example of what a machine language submission would look like: 50 00 48 50 00 65 50 00 6c 50 00 6c 50 00 6f 00 zzarrow_forwardin c++ Write a function that takes two strings and returns -1 if the first string is a substring of the second, a 1 if the second string is a substring of the first, or 0 if neither is a substring of the other.arrow_forwardWrite a function named contains-double in Scheme that takes a list as input and returns true if an item every appears twice in a row. You may assume the list is flat (i.e., no nested lists).arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





