MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / canConstruct

Method canConstruct

ConstructKPalindromeStrings.java:2–17  ·  view source on GitHub ↗
(String s, int k)

Source from the content-addressed store, hash-verified

1class Solution {
2 public boolean canConstruct(String s, int k) {
3 int n = s.length();
4 if(n < k) return false;
5 if(n == k) return true;
6 //find freq
7 int count[] = new int[26];
8 for(int i=0;i<n;i++){
9 count[s.charAt(i) - 'a']++;
10 }
11 int c=0;
12 //find odd count
13 for(int i=0;i<26;i++){
14 if((count[i]&1)==1) c++;
15 }
16 return (c<=k);
17 }
18}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected