prepbook
  • Introduction
  • Some common stuff
    • python __repr__
    • HackerRank input tips
  • Data Structures and Algorithms
    • Breadth first search
    • Depth First Search
    • Dijkstra
    • A* Search Algorithm
    • Binary Search
    • python counter
    • Sorting
      • Merge Sort
      • Quick Sort
    • Priority Queue
  • Multiprocessing vs Threading
  • Common Coding
    • Find loop in lin list
    • Maximum sum subarray
  • Coding
    • Valid palindrome
    • Palindrome number
    • Remove duplicates from sorted array
    • Island perimeter
    • Serialize and Deserialize Binary Tree
    • Valid Soduku
    • Word Pattern
    • Word Pattern II
    • Group Anagrams
    • Implement Trie
    • Deep copy list with random node
    • Palindrome Permutation
    • Combination Sum
    • Clone Graph
    • Generate parenthesis
    • Fibonacci Number
    • LRU Cache
    • Merge two sorted arrays in place
    • Hamming Distance
    • Merge K sorted arrays
    • Kth smalles element in BST
    • Kth largest element in an array
    • Remove duplicates from sorted list
    • Power of 2
    • Nested list weight sum
    • SIngle number in a list
    • Factor combinations
    • Delete node from BST
  • hacker Rank
    • Coding
      • print staircase
      • Drawing book
      • Challenge 0
      • Min-Max sum
  • WorkRelatedCoding
    • Rectangle Overlap
  • Python tips
Powered by GitBook
On this page

Was this helpful?

  1. Some common stuff

HackerRank input tips

In hacker rank, sometimes they give the input in 2 lines. The first line gives the number of items and the second line gives the items themselves in a list. This code snippet will help in getting those from the input:

'''
example input:
4
1 4 3 2
'''

import sys

n = int(raw_input().strip())
arr = map(int,raw_input().strip().split(' '))
'''
example input:
Input Format

The first line contains an integer, , total number of rows in the table. 
Each of the  subsequent lines contains  space-separated strings denoting a 
person's first name and email ID, respectively.
6
riya riya@gmail.com
julia julia@julia.me
'''

N = int(raw_input().strip())
for a0 in xrange(N):
    firstName,emailID = raw_input().strip().split(' ')
    firstName,emailID = [str(firstName),str(emailID)]

    # to locate "@" in this emailID string and get hold of the domain name, do this:
    emailDomain = emailID[(emailID.find("@")+1):]
Previouspython __repr__NextData Structures and Algorithms

Last updated 5 years ago

Was this helpful?