Sort by

recency

|

45 Discussions

|

  • + 0 comments

    Specially for the PSIT Students :)

    Here’s a brief of the “Jim and the Jokes” problem from HackerRank:

    1. Jim tells programmer jokes based on dates: a joke works if two dates (month, day) can be written as numbers in different bases so that they’re numerically equal.

    The classic example:** why do programmers mix up Christmas and Halloween? Dec 25 (in decimal, 25) = Oct 31 (in octal, 31).**

    Problem Statement Highlights:

    1. You’re given a list of special event dates (each date is a (month, day) pair).

    2. For each date, treat the month as the base and the day as the number: “day (in base month).”

    3. Find all distinct pairs of dates such that converting the day to decimal using the month's value as the base gives the same result for both dates.

    Extra Details & Constraints:

    • All numbers will use only the digits 0-9 (so bases above 10 can’t have normal digits).

    • If a day has a digit greater than or equal to the month, it’s invalid in that base, so skip that possibility.

    • You need to count all distinct pairs: if the same date appears multiple times, count all unique pairs among them (e.g., if the same pair appears 3 times, 3C2 = 3 possible jokes).

    • No need to worry about leap days.

    Here is the simple solution in CPP :

    long long check_valid(long long n, int base) {
        long long ans = 0;
        long long d = 1;
        while (n) {
            int rem = n % 10;
            if (rem >= base) return -1; // invalid digit for base
            ans += d * rem;
            d *= base;
            n /= 10;
        }
        return ans;
    }
    
    long long solve(vector<vector<int>> dates) {
        unordered_map<long long, long long> freq; // decimal value -> frequency
    
        for (auto &d : dates) {
            int base = d[0];
            long long val = d[1];
    
            if (base <= 1) continue; // skip invalid base
    
            long long res = check_valid(val, base);
            if (res == -1) continue; // invalid in that base
    
            freq[res]++;
        }
    
        long long count = 0;
        for (auto &p : freq) {
            long long n = p.second;
            if (n > 1) count += (n * (n - 1)) / 2; // nC2
        }
        return count;
    }
    

    Input: n lines of (month, day) Output: Single integer: total number of valid jokes possible with the event list.

  • + 0 comments
    from collections import defaultdict
    
    def convertDecimal(date):
        base = date[0]
        n = date[1]
        
        if base <=1:
            return -1
        
        decimal = 0
        d = 1
        while(n):
            r = n%10
            if r>=base:
                return -1
            decimal += r*d
            d*= base
            n = n//10
        return decimal
    
    def solve(dates):
        # Write your code here
        count = 0
        ans = 0
        # dates = list(set(tuple (d) for d in dates))
        di = defaultdict(int)
        for date in dates:
            x = convertDecimal(date)
            if x ==-1:
                continue
            di[x] += 1
        
        ans = 0
        for freq in di.values():
            ans += (freq * (freq - 1)) // 2
        
        return ans
    
  • + 0 comments

    Totally agree — the wording is confusing. We deal with similar clarity issues in mold reports here in Atlanta. Precise language makes all the difference!

  • + 0 comments

    if jim is out of jokes just to entertain his customers, tell jim that maybe he can sing or dance just to entertain his customer .. the real problem is how to entertain the customer .

  • + 1 comment

    100000

    12 31

    12 31

    12 31

    12 31

    12 31

    12 31 and so on for this test case how is the answer 499950000???

    12 31

    12 31