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.
for example, peh and hpe were the inputs. After converting it to uppercase we get PEH and HPE.
c[a.charAt(i) - 'A']++;
This statement inside the loop fetches the character from the string
Pass1: c['P'-'A']++ will subtract the ASCII values of P and A i.e 80-65=15. It'll increase the value at c[15] by 1.
Basically c represents all the alphabets. c[0] will hold the frequency of A, c[1] will hold the frequncy of B,... c[15] will hold the frequency of P, and so on. Then in the last loop we're just comparing all the values in array and if they're not equal thenbreak the loop by returning false
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Join us
Create a HackerRank account
Be part of a 26 million-strong community of developers
Please signup or login in order to view this challenge
Java Anagrams
You are viewing a single comment's thread. Return to all comments →