I am Kanahaiya Gupta and currently working as a Software Engineer-||| in Walmart Labs. I have started this channel to share my knowledge and experience for coding interviews.
JAVAAID is an educational initiative. It aims is to help people for building their foundation of core concepts Data Structures and Algorithms and to improve their coding skills by applying a practical approach to solve a problem which is very important because you can find the solution of any problem over the internet but there are very few resources which will tell you the approach to solve the problem.
I have just started with adding tutorials for HackerRank Solutions and many more things need to be added. We will add, as we will grow which definitely need your support. So do not forget to subscribe my channel . :)
We add tutorial every weekend. So stay tuned.!!
You can send your feedback to javaaid.connect@gmail.com
Veey nice and great explanation. Only point that I am still trying to understand is how T(0) = 1? I am thinking like if 0 steps/stairs clumbed up then this should be 0.
public static int utopianTree(int n) { // Write your code here int H=0; for(int i =0 ; i<=n ; i++){ if(i%2 == 0 ){ H = H+1; }else{ H = 2*H; } } return H; }
I know this is old. But I struggled to understand this solution. Elegant, but a bit complicated. I did it a different way that might be easier to understand. At least for me. public static void main(String[] args) { for (int period = 0; period < 9; period++ ) { int c = cycle(period); int result = period % 2 == 0 ? calculate(c) : calculate(c) - 1; System.out.println( period + " : " + result); } } public static int cycle(int period) { if( period % 2 == 0) return period / 2; return (period + 1) / 2; } public static int calculate(int cycle) { return Double.valueOf(Math.pow(2, cycle + 1)).intValue() - 1; }
Hello, thank you for this tutorial, i was able to write this using javaScript and it works function evaluateValue(s,n){ const sLength = s.length; const quotient = Math.floor(n / sLength); const r = n % sLength; const freqA = s.match(/a/g).length; const useRemainder= (r > 0) ? s.slice(0, r).match(/a/).length : 0 const a = quotient * freqA + useRemainder; return a; } evaluateValue("abc", 1000000000000);
Thanks for the tutorial.. We also can write a more concise code using java 8 string s = abc; int n=10; while(s.length()<=n){ str=str+str; } long aCount = str.substring(0,n).chars().mapToObj(c -> (char)c).filter(ch -> ch.equals('a')).count();