We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
why this code is giving me a runTime error?
I tried one of the test that is failing and I get the correct answer. I don't know why the submit is getting me an error.
staticList<String>abc=Arrays.asList("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");publicstaticList<String>weightedUniformStrings(Strings,List<Integer>queries){// Write your code hereList<String>intermediate=newArrayList<>();List<String>finalString=newArrayList<>();chara_previousChar=' ';Stringword="";for(inti=0;i<s.length();i++){chara_actualChar=s.charAt(i);if(a_previousChar==a_actualChar){word+=a_actualChar;intermediate.add(word);}else{word=String.valueOf(s.charAt(i));intermediate.add(word);}a_previousChar=s.charAt(i);}List<Integer>listInteger=newArrayList<>();for(Stringstr:intermediate){listInteger.add(getValues(str));}createfinalList(listInteger,queries,finalString);returnfinalString;}publicstaticvoidcreatefinalList(List<Integer>listInteger,List<Integer>queries,List<String>finalString){for(Integeri:queries){if(listInteger.contains(i)){finalString.add("Yes");}else{finalString.add("No");}}}publicstaticintgetValues(Stringstr){inttotal=0;for(inti=0;i<str.length();i++){total+=abc.indexOf(String.valueOf(str.charAt(i)))+1;}returntotal;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Weighted Uniform Strings
You are viewing a single comment's thread. Return to all comments →
why this code is giving me a runTime error? I tried one of the test that is failing and I get the correct answer. I don't know why the submit is getting me an error.