Saturday, February 23, 2019

Tuples - Hacker Rank Solution

Task
Given an integer, , and  space-separated integers as input, create a tuple, , of those  integers. Then compute and print the result of .

Note: hash() is one of the functions in the __builtins__ module, so it need not be imported.
Input Format
The first line contains an integer, , denoting the number of elements in the tuple.
The second line contains  space-separated integers describing the elements in tuple .
Output Format
Print the result of .
Sample Input 0
2
1 2
Sample Output 0
3713081631934410656

Tuples - Hacker Rank Solution

hash() is one of the functions in __builtins__ module, so we just need to create a tuple of the  elements and then pass it to the  function.
Problem Tester's code:
n = raw_input()
print hash(tuple([int(i) for i in raw_input().split()]))

23 comments:

  1. if __name__ == '__main__':
    n = int(raw_input())
    integer_list = map(int, raw_input().split())
    t=tuple(integer_list)
    print(hash(t))

    ReplyDelete
    Replies
    1. it worked but i still don't understand how ,how do we get this output

      Delete
    2. if __name__ == '__main__':
      n = int(raw_input())
      integer_list = map(int, raw_input().split())
      t=tuple(integer_list)
      print(hash(t))

      Delete
  2. its wrong, no loop has been used

    ReplyDelete
  3. I tried this:

    n = int(raw_input())
    a = tuple(map(int, raw_input().split('')))
    print hash(a)

    ReplyDelete
  4. #this code is working try this
    n = int(input())
    b=input()
    a = tuple(map(int, b.split(' ')))
    print(hash(a))

    ReplyDelete
    Replies
    1. yes this code working try this first

      Delete
    2. nah dude it's not working it's giving answer in negativity and value is also little bit different

      Delete
  5. n = int(input())
    b=input()
    a = tuple(map(int, b.split(' ')))
    if len(a) == n:
    print(hash(a))
    else:
    print('you have exceeded your limit')

    TRY THIS OUT!

    ReplyDelete
  6. n = int(input())
    b=input()
    a = tuple(map(int, b.split(' ')))
    if len(a) == n:
    print(hash(a))
    else:
    print('you have exceeded your limit')

    TRY THIS OUT

    ReplyDelete
  7. Best Solution is:
    if __name__ == '__main__':
    n = int(input())
    integer_list = tuple(map(int, input().split()))
    print(hash(integer_list))

    ReplyDelete
  8. n = int(input())
    integer_list = map(int, input().split())
    t=tuple(integer_list)
    print(hash(t))


    Even this worked well!

    ReplyDelete
  9. if __name__ == '__main__':
    n = int(input())
    integer_list = tuple(map(int, input().split()))
    print(hash(integer_list))

    ReplyDelete
  10. n = int(input())
    b=input()
    a = tuple(map(int, b.split(' ')))
    print(hash(a))

    ReplyDelete
  11. n=int(input())
    x=(map(int,input().split()))
    z = tuple(x)
    print(hash(z))

    # best practices

    ReplyDelete
  12. No matter which code you try, the tuple value is coming the same and not matching with hacker-rank predefined output. I tried the below code, still not working.

    n = int(input())
    inp = input().split()
    m = tuple(map(int,inp))
    print(hash(m))

    ReplyDelete
    Replies
    1. Bro I used your code using language Pypy 3 and it worked fine for me.

      Delete
    2. brah it's not working
      infact not a single code is working i had tried dozens
      n = int(input())
      integer_list = map(int, input().split())
      t = tuple(integer_list)
      print(hash(t))
      this one is also not working

      Delete

Powered by Blogger.