Sort by

recency

|

944 Discussions

|

  • + 0 comments

    Bugging out in in TypeScript. The 1, 1 test fails when it should succed.

  • + 0 comments

    The question setters missed out on an interesting test case i.e. with minutes=59 I used the conditional clause for minutes=1 only for the case minutes < 30 and it passed all the test cases. Felina Maldonado

  • + 0 comments

    C# solution:

    public static string timeInWords(int h, int m)
        {
            string outputPrint = string.Empty;
            Dictionary<int, string> numbersTime = new Dictionary<int, string>
            {
                { 0, "o' clock" }, { 1, "one" }, { 2, "two" }, { 3, "three"}, { 4, "four"},
                { 5, "five"}, { 6, "six"}, { 7, "seven"}, { 8, "eight"}, { 9, "nine"},
                {10, "ten"}, {11, "eleven"}, {12, "twelve"}, {13, "thirteen"}, {14, "fourteen"},
                {15, "quarter"}, {16, "sixteen"}, {17, "seventeen"}, {18, "eighteen"},
                {19, "nineteen"}, {20, "twenty"}, {21, "twenty one"}, {22, "twenty two"},
                {23, "twenty three"}, {24, "twenty four"}, {25, "twenty five"}, {26, "twenty six"},
                {27, "twenty seven"}, {28, "twenty eight"}, {29, "twenty nine"}, {30, "half"}
            };
            switch (m)
            {
                case 0:
                    outputPrint = numbersTime[h] + " " + numbersTime[0];
                    break;
                case 15:
                    outputPrint = numbersTime[m] + " past " + numbersTime[h];
                    break;
                case 30:
                    outputPrint = numbersTime[m] + " past " + numbersTime[h];
                    break;
                case 45:
                    outputPrint = numbersTime[60 - m] + " to " + numbersTime[h + 1];
                    break;
                case <=10:
                    outputPrint = numbersTime[m] + " minute past " + numbersTime[h];
                    break;
                case <= 30:
                    outputPrint = numbersTime[m] + " minutes past "+ numbersTime[h];
                    break;
                case >30:
                    outputPrint = numbersTime[60 - m] + " minutes to " + numbersTime[h+1];
                    break;
            }
            return outputPrint;
        }
    
  • + 0 comments

    C++ Solution

    const map<int, string> nums{
        {1, "one"}, {2, "two"}, {3, "three"}, {4, "four"}, {5, "five"},
        {6, "six"}, {7, "seven"}, {8, "eight"}, {9, "nine"}, {10, "ten"},
        {11, "eleven"}, {12, "twelve"}, {13, "thirteen"}, {14, "fourteen"},
        {15, "quarter"}, {16, "sixteen"}, {17, "seventeen"}, {18, "eighteen"},
        {19, "nineteen"}, {20, "twenty"}, {21, "twenty one"}, {22, "twenty two"},
        {23, "twenty three"}, {24, "twenty four"}, {25, "twenty five"},
        {26, "twenty six"}, {27, "twenty seven"}, {28, "twenty eight"},
        {29, "twenty nine"}, {30, "thirty"}};
        
    string timeInWords(int h, int m) {
      
      if (m == 0) {
        return nums.at(h) + " o' clock";
      } else
      if(m > 30) {
        m = 60 - m;
        
        return nums.at(m) + 
          (m != 15 ? ((m == 1 || m == 21) ? " minute" : " minutes") : "") +
          " to " + nums.at((h+1 < 12) ? h+1 : 1);
      } else 
      if (m == 30) {
        return "half past " + nums.at(h);
      } else {
        return nums.at(m) + 
          (m != 15 ? ((m == 1 || m == 21) ? " minute" : " minutes") : "") +
          " past " + nums.at(h);
      }
    }
    
  • + 0 comments
    def timeInWords(h, m):
        num_words = {
            1: "one", 2: "two", 3: "three", 4: "four", 5: "five", 6: "six",
            7: "seven", 8: "eight", 9: "nine", 10: "ten", 11: "eleven",
            12: "twelve", 13: "thirteen", 14: "fourteen", 15: "quarter",
            16: "sixteen", 17: "seventeen", 18: "eighteen", 19: "nineteen",
            20: "twenty", 21: "twenty one", 22: "twenty two", 23: "twenty three",
            24: "twenty four", 25: "twenty five", 26: "twenty six", 27: "twenty seven",
            28: "twenty eight", 29: "twenty nine", 30: "half"
        }
        
        if m == 0:
            return f"{num_words[h]} o' clock"
        
        if m == 15 or m == 30:
            return f"{num_words[m]} past {num_words[h]}"
        
        if m == 45:
            next_hour = h + 1 if h < 12 else 1
            return f"quarter to {num_words[next_hour]}"
        
        if m < 30:
            minute_word = "minute" if m == 1 else "minutes"
            return f"{num_words[m]} {minute_word} past {num_words[h]}"
        
        next_hour = h + 1 if h < 12 else 1
        minute_word = "minute" if (60 - m) == 1 else "minutes"
        return f"{num_words[60 - m]} {minute_word} to {num_words[next_hour]}"