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.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Strings
  4. String Construction
  5. Discussions

String Construction

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 896 Discussions, By:

recency

Please Login in order to post a comment

  • davidabbs_abbs1
    5 days ago+ 0 comments

    Python Solution

    def stringConstruction(s): return len(set(s))

    0|
    Permalink
  • gopalsankar2003
    1 week ago+ 0 comments

    80% My Java Solution

        public static int stringConstruction(String s) {
        HashMap<Character, Integer> countChar = new HashMap<Character, Integer>();
        char[] s_char = s.toCharArray();
        for(int i=0; i<s.length(); i++)
        {
            if(!countChar.containsKey(s_char[i]))    
            {
                countChar.put(s_char[i],1);
            }
        }
        return countChar.size();
        }
    
    0|
    Permalink
  • serg_lugovoy_81
    1 week ago+ 0 comments

    JavaScript one line

    function stringConstruction(s) {
        return new Set([...s]).size
    }
    
    0|
    Permalink
  • grbz_kerem
    2 weeks ago+ 0 comments

    JavaScript Solution

    function stringConstruction(s) {
      let [i, sLength, cost] = [0, s.length, 0];
      while (i < sLength) {
        if (!s.slice(0, i).includes(s[i])) cost++;
        i++;
      }
      return cost;
    }
    
    0|
    Permalink
  • mohamedhossamma1
    3 weeks ago+ 0 comments
    • c language
    int stringConstruction(char* s)
    {
        int max=0;int count=0;
        for( int i = 0 ; i<strlen(s);i++)
        {
           if(s[i]>max)
           {
               max = s[i];
           }
            
        }
        int *arr = (int*)calloc(max+1,sizeof(int));
        
     for(int i = 0 ; i<strlen(s);i++)
        {
          arr[s[i]]++;        
        }
      for(int i = 0 ; i<=max;i++)
        {
          if(arr[i]>0)
          {
              count++;
              arr[i]=0;
          }
        }  
        free(arr);
        return count;
    
    }
    
    0|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy