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

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Strings
  4. Weighted Uniform Strings
  5. Discussions

Weighted Uniform Strings

Problem
Submissions
Leaderboard
Discussions
Editorial

    You are viewing a single comment's thread. Return to all comments →

  • deep099
    3 months ago+ 0 comments
    public static List<String> weightedUniformStrings(String s, List<Integer> queries) {
        // Write your code here
        Set<Integer> st=new HashSet<Integer>();
        
        char c=s.charAt(0);
        int wt=((int)c-96);
        st.add(wt);
        
        for(int i=0;i<s.length();i++)
        {
            if(s.charAt(i)!=c)
            {
                c=s.charAt(i);
                wt=((int)c)-96;
                st.add(wt);
            }
            else
            {
                wt+=((int)c-96);
                st.add(wt);
            }
        }
        List<String> str=new ArrayList<String>();
        System.out.println(st);
        for(int x: queries)
        if(st.contains(x))
        str.add("Yes");
        else
        str.add("No");
        
        return str;
        
    
        }
    
    1|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy