Sachdefine
BAN USER
- 0of 0 votes
AnswerDebugging testcases if a web site is opening in US but not in India
- Sachdefine in India for Kindle| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer Testing
public class LongestPalindrome {
public static void main(String[] args) {
String str = "ABCBAHELLOHOWRACECARAREYOUIAMAIDOINGGOOD";
System.out.println("Longest Palindrome: "+longestPalindrome(str));
}
public static String longestPalindrome(String str){
String longestPalindrome = null;
if(null==str)
return null;
else{
longestPalindrome=str.substring(0,1);
for(int i=0;i<str.length()-1;i++){
String palindrome=expand(str,i,i);
if(palindrome.length()>1)
System.out.println(palindrome);
if(palindrome.length()>longestPalindrome.length()){
longestPalindrome=palindrome;
}
palindrome=expand(str,i,i+1);
if(palindrome.length()>1)
System.out.println(palindrome);
if(palindrome.length()>longestPalindrome.length()){
longestPalindrome=palindrome;
}
}
}
return longestPalindrome;
}
static String expand(String str, int left, int right){
if(left>right)
return null;
else{
while(left>=0 && right<str.length()&&str.charAt(left)==str.charAt(right)){
right++;
left--;
}
}
return str.substring(left+1,right);
}
}
public static void HashTableUse(String str){
LinkedHashMap <Character, Integer> ht=new LinkedHashMap <Character, Integer>();
String finalo=new String();
for(int i=0;i<str.length();i++){
if(ht.containsKey(str.charAt(i))){
ht.put(str.charAt(i), ht.get(str.charAt(i))+1);
}else
ht.put(str.charAt(i), 1);
}
System.out.println(ht);
for(Map.Entry<Character, Integer> entry: ht.entrySet()){
finalo=finalo+entry.getValue()+entry.getKey();
}
System.out.println(finalo);
}
public class RepeatedCharAsCount {
public static void main(String[] args) {
String str="aaabbbbccccdddddddddddddddd";
String finalo = new String();
int count=1,i;
for(i=0;i<str.length()-1;i++){
if(str.charAt(i)==str.charAt(i+1))
count++;
else{
finalo=finalo+count+str.charAt(i);
count=1;
}
}
finalo=finalo+count+str.charAt(i);
System.out.println(finalo);
}
}
public class ShortStringIsPartOfMainString {
public static void main(String[] args) {
String mainStr="abcabcabd";
String shortStr="abcabd";
int j = 0;
boolean bool=false;
if(mainStr.length()>shortStr.length()){
for(int i=0;i<mainStr.length();i++){
if(j<shortStr.length()&&mainStr.charAt(i)==shortStr.charAt(j)){
j++;
if(j==shortStr.length()){
System.out.println("Yes string is present in main");
bool=true;
break;
}
}else{
j=0;
}
}
if(!bool)
System.out.println("String not present in main");
}else
System.out.println("Main string is smaller than short one");
}
}
Complexity is O(n)
- Sachdefine January 23, 2014public void FirstNonRepeatedCharacter(String str){
HashSet hs=new HashSet();
boolean bool=false;
for(int i=0;i<str.length();i++){
if(!hs.add(str.charAt(i))){
bool=true;
System.out.println("First Non repitive char is "+str.charAt(i));
break;
}
}
if(!bool)
System.out.println("None of chars are repeating");
}
Strings objects are immutable. Means we can not modify strings. Whenever we try to modify string object a new object is created internally. To understand the immutability of string we can take an example of string addition
String str="XYZ";
System.out.println(str.concat("ABC"));
System.out.println(str);
Here output of 1st sop will be XYZABC whereas for next sop output will be XYZ.
It indicates that a new string is created while we did concat on str but str is not changed.
And StringBuilder and StringBuffer are mutable.
Now difference between StringBuilder and StringBuffer. Although functionality wise there is no difference except StringBuffer are synchronized. If you are developing single threaded app and your string is getting modified frequently then to get best performance StringBuilder is best option in comparison to StringBuffer. Since StringBuffer is synchronized to its bit slow.
Brute Force
public static void maintainOrder(String str) {
String finalStr=new String();
for(int i=0;i<str.length();i++){
if(!finalStr.contains(""+str.charAt(i))){
finalStr=finalStr+str.charAt(i);
}
}
System.out.println(finalStr);
}
Guys the same question was asked by me as well in amazon interview. Whatever till now we all have mentioned here is not sufficient. What I have analysed, while answering these type of question do not give generalized statements. It should be more technical, related to performance, mime type, compatibility etc
- Sachdefine January 15, 2014there was one more condition that once you taken out water from the pool you can not put back.
- Sachdefine January 13, 2014See the water which has been thrown out is only 3L which is in step 4th that is 2, 0, 3
- Sachdefine January 11, 2014In Java its very simple if I use linkedhashmap to keep the alphabet as key and count as value.
- Sachdefine January 11, 2014But I can see only 3 Ltr wastage.
- Sachdefine January 11, 2014Fantastic answer.. I don't think it can be optimized more.
- Sachdefine January 11, 2014
Repyahviross, translator at learnify
Dedicated English-Mandarin Chinese translator with years of experience working in professional and scientific communities.Diverse translation work including proprietary scientific ...
RepShayneLJohnson, Scientific Officer at Cerberus Capital
I'm Shayne and I have a history of sensitivities that range from dietary issues to skin care and other ...
Repryanahurd, Korean Air Change Flight at 247quickbookshelp
Je suis Ryana avec 2 ans d'expérience dans la gestion d'un flux de travail à haut volume en ...
Repvaleriecfranks, Computer Scientist at ASAPInfosystemsPvtLtd
A strong writer with a passion for story-telling who has extensive experience of writing literary compositions, articles, reports, books and ...
Repmerrillagreerm, Android Engineer at Abs india pvt. ltd.
I am patient, compassionate, and caring when treating and counseling patients in practice, making them feel like they’re in ...
Repannawellson007, Area Sales Manager at 8x8
Hey my name is anna And i am working as a content writer in Search engine optimization company.My component ...
Repalinehchavez, SHOT 1500 NIGHT 5000 Call girls in Munirka Metro 9711794795 at Apple
Hi, I am Aline From New York USA. I am working as a Real estate rental agent in an Energy ...
Reptaylorjose221, Production Engineer at BT
Graphic designer with a strong background in marketing design.Having a day off during the week to do whatever I ...
Repadak4257, Applications Developer at Adobe
I am fond of Listening Songs then reading newspapers which are all about a story of a beautiful nature and ...
Repman254183, Project Leader at GoDaddy
I am working as Human Resources Associates, and my duties are for obtaining, recording, and interpreting human resources information within ...
Repprishamondel, Quality Assurance Engineer at Bloomberg LP
I am Prisha, a versatile self-starter and a quick learner looking for a position within your company, Netaid. My hobbies ...
RepIndianastrologyguru, Data Scientist at ABC TECH SUPPORT
Hey I'm Shelly Renee and I'm working as a system developer. Currently working part time on a project ...
Replouisefbray, Integration Software Engineer at Ask.com
Hey! My name is Louise and I am a computer hardware retailer and wholesaler.I also provide services online. My ...
Reploragurrero, Research Scientist at Absolute Softech Ltd
I am Lora , an empathetic and dedicated Community Organizer with a deep passion for helping others and a strong determination ...
RepHelanZelda, Consultant at Advent
HelanZelda from Atlanta, GA, United States. I have a passion for exploring/sharing new ideas and experiences throughout the interdisciplinary ...
}
- Sachdefine March 01, 2014