diksha2207
BAN USER
Comments (2)
Reputation 0
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
Java Implementation:
public static void modifyString()
{
Scanner sc = new Scanner(System.in);
String sInput = sc.nextLine();
int iChanges = 0;
sInput = sInput.replace('a', '+');
sInput = sInput.replace('A', '+');
sInput = sInput.replace('E', '+');
sInput = sInput.replace('e', '+');
sInput = sInput.replace('i', '+');
sInput = sInput.replace('I', '+');
sInput = sInput.replace('o', '+');
sInput = sInput.replace('O', '+');
sInput = sInput.replace('u', '+');
sInput = sInput.replace('U', '+');
for(int i=0; i< sInput.length(); i++)
{
if(sInput.charAt(i) == '+')
{
iChanges++;
}
}
System.out.println("Modified String: " + sInput);
System.out.println("Changes made: " + iChanges);
}
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
What I understand from the problem statement: You need to find the index of the first word that starts with the letter 'a'. For that read the input array from the System.in and break at the point when you find first word with first character as 'a'. Please correct me if my understanding is wrong:
Worst case time complexity: O(n) - assuming last array item starts with 'a'.
- diksha2207 May 12, 2017Best case time complexity: O(1) - assuming first array item starts with 'a'.
Average case time complexity: O(n) - assuming middle array item starts with 'a'.