Sort by

recency

|

958 Discussions

|

  • + 0 comments

    My python solution:

    def timeInWords(h, m):

    nums = ["one",'two','three','four','five','six','seven','eight','nine','ten','eleven','tweleve', 'thirteen', 'fourteen',15,'sixteen', 'seventeen', 'eighteen','nineteen','twenty','twenty one','twenty two','twenty three', 'twenty four','twenty five','twenty six','twenty seven','twenty eight', 'twenty nine']
    
    phrases = {0:"o' clock", 
           15:"quarter past", 30:'half past', 
           45:"quarter to", }
    if m==1 and h==1:
        return 'one minute past one'
    if m==0:
        return nums[h-1]+' '+phrases[m]
    elif m==45:
        return phrases[m]+' '+nums[h]
    elif m==15:
        return phrases[m]+' '+nums[h-1]
    elif m==30:
        return phrases[m]+' '+nums[h-1]
    elif 1<=m<=30:
        return nums[m-1]+' minutes past '+ nums[h-1]
    else:
        k=60-m
        return nums[k-1]+' minutes to '+nums[h]
    
  • + 0 comments

    Nice — solving the same problem in five languages is a great way to compare idioms. Below I’ll give concise, actionable feedback you can apply to each implementation (correctness, edge cases, style, tests), plus language-specific tips. 11xplay Sign Up

  • + 1 comment

    My java solution. Not all tests pass and i don't understand why. If i test them by hand they pass, but sending solution makes them not pass (for example test 2)

    class Result {

    /*
     * Complete the 'timeInWords' function below.
     *
     * The function is expected to return a STRING.
     * The function accepts following parameters:
     *  1. INTEGER h
     *  2. INTEGER m
     */
    
     private static final String[] NUMBERS = {
        "", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten",
        "eleven", "twelve", "thirteen", "fourteen", "quarter", "sixteen", "seventeen",
        "eighteen", "nineteen", "twenty", "twenty one", "twenty two", "twenty three",
        "twenty four", "twenty five", "twenty six", "twenty seven", "twenty eight",
        "twenty nine", "half"
    };
    
    public static String timeInWords(int h, int m) {
    // Write your code here
    StringBuilder b = new StringBuilder();
    if(m > 0 && m <= 30) {
        System.out.print(NUMBERS[m] + " past " + NUMBERS[h]);
        b.append(NUMBERS[m] + " past " + NUMBERS[h]);
    } else if(m > 30) {
        System.out.print(NUMBERS[60-m] + " minutes to " + NUMBERS[h+1]);
        b.append(NUMBERS[60-m] + " minutes to " + NUMBERS[h+1]);
    } else {
        System.out.print(NUMBERS[h] + " o' clock");
        b.append(NUMBERS[h] + " o' clock");
    }
    return b.toString();
    }
    

    }

    Not all

  • + 1 comment

    it seems to be an easy problem, however, work it out took me a lot of time.

    There are too many details and corner case to handle.

  • + 0 comments

    Here is problem solution in Python, Java, C++, C and Javascript - https://programmingoneonone.com/hackerrank-the-time-in-words-problem-solution.html