conv3d
conv3d

Reputation: 2896

hackerrank problem runs fine in jupyter but fails in hackerrank

I'm not sure what's going on with this problem.

I place the exact same code in a jupyter notebook and everything runs fine. But when I place the code in Hackerrank it does not return any output.

Does anyone spot the error here?

Sample:

6 4

give me one grand today night

give one grand today

#!/bin/python3

import math
import os
import random
import re
import sys
from collections import Counter

# Complete the checkMagazine function below.
def checkMagazine(magazine, note):
    ds = Counter(magazine)
    for m in note:
        ds[m] = ds[m] - 1
        if ds[m] < 0 or ds[m] is None: return 'No'
    return 'Yes'

if __name__ == '__main__':
    mn = input().split()

    m = int(mn[0])

    n = int(mn[1])

    magazine = input().rstrip().split()

    note = input().rstrip().split()

    checkMagazine(magazine, note)

Upvotes: 1

Views: 500

Answers (1)

ggorlen
ggorlen

Reputation: 56983

This code returns but doesn't print the output to stdout that the HR code runner is looking for. Try print(checkMagazine(magazine, note)).

In general, HR is a bit fussy about IO. Data will be read through stdin and will be printed to stdout, often in bizarre formats like "Yes" or "Impossible!" for a function that would normally return a boolean.

Upvotes: 4

Related Questions