This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# There are a number of people who will be attending ACM-ICPC World Finals. Each of them may be well versed in a number of topics. Given a list of topics known by each attendee, presented as binary strings, determine the maximum number of topics a 2-person team can know. Each subject has a column in the binary string, and a '1' means the subject is known while '0' means it is not. Also determine the number of teams that know the maximum number of topics. Return an integer array with two elements. The first is the maximum number of topics known, and the second is the number of teams that know that number of topics. | |
# Example | |
# The attendee data is aligned for clarity below: | |
# 10101 | |
# 11110 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Question | |
attr_accessor :prompt, :answer | |
def initialize(prompt, answer) | |
@prompt = prompt | |
@answer = answer | |
end | |
end | |
p1 = "What color are apples?\n(a)red (b)purple (c) orange" | |
p2 = "What color are bananas?\n(a)pink (b)red (c) yellow" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Lisa just got a new math workbook. A workbook contains exercise problems, grouped into chapters. Lisa believes a problem to be special if its index (within a chapter) is the same as the page number where it's located. The format of Lisa's book is as follows: | |
# There are chapters in Lisa's workbook, numbered from to . | |
# The chapter has problems, numbered from to . | |
# Each page can hold up to problems. Only a chapter's last page of exercises may contain fewer than problems. | |
# Each new chapter starts on a new page, so a page will never contain problems from more than one chapter. | |
# The page number indexing starts at . | |
# Given the details for Lisa's workbook, can you count its number of special problems? | |
# Example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# You are given an unordered array consisting of consecutive integers [1, 2, 3, ..., n] without any duplicates. You are allowed to swap any two elements. Find the minimum number of swaps required to sort the array in ascending order. | |
# Example | |
# Perform the following steps: | |
# i arr swap (indices) | |
# 0 [7, 1, 3, 2, 4, 5, 6] swap (0,3) | |
# 1 [2, 1, 3, 7, 4, 5, 6] swap (0,1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# There is a new mobile game that starts with consecutively numbered clouds. | |
# Some of the clouds are thunderheads and others are cumulus. The player can jump | |
# on any cumulus cloud having a number that is equal to the number of the current | |
# cloud plus 1 or 2. The player must avoid the thunderheads. Determine the minimum | |
# number of jumps it will take to jump from the starting postion to the last cloud. | |
# It is always possible to win the game. | |
# For each game, you will get an array of clouds numbered 0 if they are safe or 1 | |
# if they must be avoided. | |
# Example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# An avid hiker keeps meticulous records of their hikes. During the last hike that | |
# took exactly steps, for every step it was noted if it was an uphill, , or a | |
# downhill, step. Hikes always start and end at sea level, and each step up or down | |
# represents a unit change in altitude. We define the following terms: | |
# A mountain is a sequence of consecutive steps above sea level, starting with a step | |
# up from sea level and ending with a step down to sea level. | |
# A valley is a sequence of consecutive steps below sea level, starting with a step | |
# down from sea level and ending with a step up to sea level. | |
# Given the sequence of up and down steps during a hike, find and print the number |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ShoppingCart(object): | |
def __init__(self): | |
self.total = 0 | |
self.items = {} | |
def add_item(self, item_name, quantity, price): | |
self.total += price*quantity | |
self.items.update({item_name: quantity}) | |
def remove_item(self, item_name, quantity, price): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Divide to even as part possible | |
# The method is to return a list of the even possible path | |
# This is the link to understand the algebra; | |
# https://math.stackexchange.com/questions/1791795/dividing-an-integer-into-a-fixed-number-of-integers | |
def splitInteger(num,parts): | |
if num > parts: | |
ls =[] | |
for i in range(1,parts+1): | |
ls.append(i*num//parts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime, timedelta | |
import urllib.parse | |
import requests | |
def openAndClosePrices(firstDate, lastDate, weekDay): | |
hacker_stock='https://jsonmock.hackerrank.com/api/stocks/search?key=value' | |
page=1 | |
url=hacker_stock+urllib.parse.urlencode({ 'page': page}) | |
json_data=requests.get(url).json() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Assume we have a list of words from the English dictionary, like: | |
# EnglishWords: "water","big","apple","watch","banana","york","amsterdam","orange","macintosh","bottle","book" | |
# And another long list of string to process, write a function to identify "compound words" and return them: | |
# input: "paris","applewatch","ipod","amsterdam","bigbook","orange","waterbottle" | |
# output: "applewatch","bigbook","waterbottle | |
def comp_wrd(engWords, inpWords): | |
output = [] |