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.
}
//arr[i]=(s.charAt(i)-'a'+1);
}
Set<Integer> weights = new HashSet<>();
for (int weight : arr) {
weights.add(weight); // Store all unique weights in a set
}
List<String> result = new ArrayList<>();
for (int query : queries) {
if (weights.contains(query)) {
result.add("Yes"); // Check if the query weight exists
} else {
result.add("No");
}
return result;
}
}
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 →
There is a problem with my code rectify this anyone please
int[] arr=new int[s.length()]; List l=new ArrayList<>(); // arr[0]=int(s.charAt(0)-96); int cnt=0; for(int i=0;i0 && s.charAt(i-1)==s.charAt(i)) { cnt++; arr[i]=arr[i-1]*cnt; } else { cnt=1; // arr[i]=(s.charAt(i)-'a'+1);
}