Pawan Kishor Singh
BAN USER 0of 0 votes
AnswersGiven a string of n characters how would you replace all occurrences of a particular character with some other character with a time complexity less than O(n)?
 Pawan Kishor Singh in India
Note: W/o using any inbuilt string replace functions of the language. Report Duplicate  Flag  PURGE
Adobe Coding
Isn't it same as a palindrome check question? If yes, here is the java code:
public class Test {
static boolean isPowerList(int[] arr){
//Take 2 pointers one starts forward from 0 and another starts from end backwards
int i=0, j=arr.length1;
while (i<j){
if (arr[i++] != arr[j]){
return false;
}
}
return true;
}
public static void main(String[] args) {
int[] arr1 = {1,2,1};
int[] arr2 = {1,2,3,4,5,6,7,6,5,4,3,2,1,1};
int[] arr3 = {1,2,3,4,5,6,1000,6,5,4,3,2,1};
System.out.println(isPowerList(arr1)); //true
System.out.println(isPowerList(arr2)); //false
System.out.println(isPowerList(arr3)); //true
}
}

Pawan Kishor Singh
October 17, 2020 Good. This is another way to look at it.
In more general terms : Given a number x, next number in the series is: 2x+2.
The question mentioned "Person A is in building 1 and person B is in building 106" . I suppose this is the state at minute0 and time starts from here. So, they will meet when 7 minutes would've just completely passed.
Time A @ B @
0 1 106
1 6 96
2 11 86
3 16 76
4 21 66
5 26 56
6 31 46
7 36 36
I think you are right. Given the fact that measurement unit of rain is onedimensional (in inch, cm, or mm...per year), your equation means:
Total Volume of rain poured on earth in a year= average rain on the planet in mm *surface area of the planet in square mm
No. of rain drops pouring on earth every year=Total Volume of rain poured on earth in a year in cubic mm/average volume of a rain drop in cubic mm
I think its about specifying optional arguments in a function (in C++).
The way function divide has been defined, it causes specifying the other argument b optional. That means you can call divide function in any of following 2 ways:
divide(10) //in this case other variable will be assumed to be 2
divide(10,5) //in this case other variable will be 5. b=2 will be ignored.
Another approach to do it in 4 iterations:
1) Create 4 groups  2 balls each, Say group A, B, C and D.
2) compare weight of each group  3 iterations
3) After that you know which group is oddoneout. Lets say it is group D (or faulty group).
4) Now take 1 good ball from any of the good groups A, B or C. Take any ball from D group.
if weight of the ball from group D == weight of the ball from good group
 the other ball from group D is the answer.
else
 the ball which you are holding of group D is the answer.
RepKimRPierce, Employee at Achieve Internet
I am a customer serviceoriented Travel Agent in Travel and Tourism industries. I strongly believe that the skills and abilities ...
Open Chat in New Window
In asymptomatic analysis n is considered to be very very large. Hence I'm sure your value of n would be small which might be showing deviation. But in general for large values of n exponentials always dominate fixed powers.
 Pawan Kishor Singh October 17, 2020