Sort by

recency

|

1032 Discussions

|

  • + 0 comments

    Here is my c++ solution, you can watch the explanation here : https://youtu.be/EhPgZkwwx4Y

    int libraryFine(int d1, int m1, int y1, int d2, int m2, int y2) {
        int res = 0;
        if(y1<y2 || (y1 == y2 && m1<m2) || (y1 == y2 && m2 == m1 && d1<=d2)) return 0;
        if(y2 == y1){
            if(m1 == m2) return 15 * (d1 - d2);
            else return (m1 - m2) * 500;
        }
        else return 10000;
        return 0;
    }
    
  • + 0 comments
        if(y1==y2 and m1==m2 and d1>d2):
            return 15*(d1-d2)
        elif(y1==y2 and m1>m2):
            return 500*(m1-m2)
        elif(y1>y2):
            return 10000
        else:
            return 0
    
  • + 0 comments
    def libraryFine(d1, m1, y1, d2, m2, y2):
        # If the book is returned after the expected year
        if y1 > y2:
            return 10000
        # If the book is returned in the same year but after the expected month
        elif y1 == y2 and m1 > m2:
            return (m1 - m2) * 500
        # If the book is returned in the same year and month but after the expected day
        elif y1 == y2 and m1 == m2 and d1 > d2:
            return (d1 - d2) * 15
        # If the book is returned on or before the due date
        else:
            return 0
    
  • + 0 comments
    def libraryFine(d1, m1, y1, d2, m2, y2):
        if y1 > y2:
            return 10000
        if y1 == y2:
            if m1 > m2:
                return 500 * (m1 - m2)
            if m1 == m2 and d1 > d2:
                return 15 * (d1 - d2)
        return 0
    
  • + 0 comments

    Here is my Python solution! It looks a bit complicated but is just a series of if, elif, and else statements to calculate the fine.

    def libraryFine(d1, m1, y1, d2, m2, y2):
        if y1 < y2:
            return 0
        elif y1 == y2:
            if m1 < m2:
                return 0
            elif m1 == m2:
                if d1 <= d2:
                    return 0
                else:
                    return 15 * (d1 - d2)
            else:
                return 500 * (m1 - m2)
        else:
            return 10000