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. Dynamic Programming
  4. Abbreviation
  5. Discussions

Abbreviation

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 597 Discussions, By:

recency

Please Login in order to post a comment

  • nandlalinks61
    2 weeks ago+ 0 comments

    It appears that you've mentioned the term "Abbreviation." Could you kindly offer more details or context regarding the specific word or phrase for which you are seeking an abbreviation? Abbreviations are concise forms of words or expressions, and having clarity on the term you wish to abbreviate would assist me in providing the accurate abbreviation for your request.

    0|
    Permalink
  • nam_vuhoang
    2 months ago+ 0 comments

    Java:

    public static String abbreviation(String a, String b) {
        int m = a.length();
        int n = b.length();
        if (m < n) {
          return "NO";
        }
        
        boolean[][] isValid = new boolean[m + 1][n + 1];
        isValid[0][0] = true;
        
        for (int i = 1; i <= m; i++) {
          char ca = a.charAt(i - 1);
          // mark if this character can be skipped
          boolean canBeSkipped = Character.isLowerCase(ca);
          isValid[i][0] = canBeSkipped;
              
          for (int j = 1; j <= n; j++) {
            char cb = b.charAt(j - 1);
            boolean matches = Character.toUpperCase(ca) == cb;
            isValid[i][j] = (matches && isValid[i-1][j-1]) || 
                    (canBeSkipped && isValid[i-1][j]); 
          }
        }
    //    System.out.println(
    //        Arrays
    //          .deepToString(isValid)
    //          .replace("true", "1")
    //          .replace("false", "0")
    //          .replace("],", "],\n"));
        return isValid[m][n] ? "YES" : "NO";
      }
    
    }
    
    0|
    Permalink
  • shaguftashamid66
    2 months ago+ 0 comments

    An abbreviation is a shortened form of a word or phrase, typically consisting of one or more letters, which is used to represent the full word or phrase login. Abbreviations are commonly used in written and spoken language to save time and space. Some examples of abbreviations include:

    Dr.: Abbreviation for "Doctor." Ave.: Abbreviation for "Avenue." etc.: Abbreviation for "et cetera," meaning "and so on" or "and others." Jan.: Abbreviation for "January." Mr.: Abbreviation for "Mister." e.g.: Abbreviation for "exempli gratia," meaning "for example." Ph.D.: Abbreviation for "Doctor of Philosophy." Inc.: Abbreviation for "Incorporated," often used in company names.

    0|
    Permalink
  • tomdanny01
    3 months ago+ 0 comments

    It passes the test cases, but if there are any optimization possibilities that I missed, kindly let me know! Defined acronyms (a, b): # Enter your program here If dp = "" for l in a, then # New set of potential routes to takel_upper = l.upper() and _dp = set()

    • Continuing previous Possible pre-DP routes included:

          Only lowercase letters will be permitted if prior == b and l.islower() returns true. Lowercase letters are the only characters that will be accepted if path already equals b.
                  following new_dp.add(prev)
      
    • A new route has been suggested: prev + l_upper = new_prev

    • Uppercase characters must be added; otherwise, the entire route is invalid new_dp.add(new_prev) if b.startswith(new_prev) and l.isupper()

    • Lowercase letters can be inserted if the l.islower() function returns true. Lowercase letters cannot be introduced if b.startswith(new_prev) returns true. new_dp.add(new_prev) new_dp.add(prev)

      # Replace any additional possible pathways with dp = new_dp.
      

      return "YES" if b is in dp and "NO" otherwise.

    0|
    Permalink
  • michaeldavidlu
    3 months ago+ 0 comments
    def abbreviation(a, b):
        # Write your code here
        results, valid, last = {''}, False, False
        for i, char in enumerate(a):
            new = set()
            last = i == len(a) - 1
            for result in results:
                less = len(result) < len(b)
                if char.isupper():
                    if last: valid = result + char == b
                    elif less: new.add(result + char)
                else:
                    temp = result + char.upper()
                    if last: valid = b == result or b == temp
                    if not last:
                        new.add(result)
                        if less and b.startswith(temp): new.add(temp)
                if last and valid: return 'YES'
            results = new
        return 'NO'
    
    1|
    Permalink
Load more conversations

Need Help?


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