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.
NO ! its not how you are imagining it to be. what the code is doing is creating an array of 26 elements (for 26 alphabets in english). so c[0] = A, c[1] = B...and so on . now he is traversing the string and for each index in the string the value of that elements in the array increases by 1 . therefore, if there are 2 A's in the string then c[0] = 2 and so on . he does this for both the strings and then checks if the position and respective values match or not
if they match then they are anagrams else not
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 →
NO ! its not how you are imagining it to be. what the code is doing is creating an array of 26 elements (for 26 alphabets in english). so c[0] = A, c[1] = B...and so on . now he is traversing the string and for each index in the string the value of that elements in the array increases by 1 . therefore, if there are 2 A's in the string then c[0] = 2 and so on . he does this for both the strings and then checks if the position and respective values match or not
if they match then they are anagrams else not