amish.cusat
BAN USER- 0of 0 votes
AnswersGiven a number, you have to replace digits of the number with a given character 'a' and print all such possible strings(replacing only 1 digit or more at a time). The constraint is that no 2 consecutive digits should be replaced.
- amish.cusat in India| Report Duplicate | Flag | PURGE
Amazon Developer Program Engineer
Yeah I missed that part...the condition should have been if(startNum > 1)
- amish.cusat June 05, 2014private static int findMinNumWithDigitProductN(int n){
int startNum = n;
int result = 0;
List<Integer> resultList = new ArrayList<Integer>();
for( int i = 9 ; i > 1 ; i--){
while( startNum % i == 0){
resultList.add(i);
startNum = startNum/i;
}
}
if(n == startNum)
return -1;
for(int i = resultList.size() ; i > 0 ; i--){
result = result*10 + resultList.get(i-1);
}
return result;
}
- amish.cusat June 05, 20148 races
- amish.cusat June 03, 2014What if s16 is faster than s2...how can you eliminate it.
- amish.cusat June 03, 2014In step 3, instead of checking for just one character, better choice is to check for the palindrom. If the substring between front and back pointer(skipping front) is palindrom then front is the odd char or else back is the odd char
{{if(isPalin(str.substring(front, back+2)))
return charArray[front-1];
else if(isPalin(str.substring(front-1, back+1)))
return charArray[back+1];}}
use hashset as it does't allow duplicates..time complexity to add elements would be O(n).
- amish.cusat June 01, 2014
time complexity will be too much in case if we use pointers to reverse the first half of list twice.
- amish.cusat June 25, 2014