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
/* THE FOLLOWING CODE HAS BEEN COMPILED IN DOS TURBO C++ | |
*/ | |
#include<iostream.h> | |
#include<conio.h> | |
int highestPowerof2(int n) | |
{ | |
int res = 0; |
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 Solution: | |
def monotoneIncreasingDigits(self, N: int) -> int: | |
n=N | |
if n==10: | |
return 9 | |
if n<10: | |
return n | |
arr=[int(i) for i in str(n)] | |
for i in range (len(arr)-1): | |
if arr[i]>arr[i+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
#Method1 : | |
class Solution: | |
def wordPattern(self, pattern: str, str: str) -> bool: | |
map_words={} | |
map_chars={} | |
words=str.split(' ') | |
if len(words)!=len(pattern): | |
return False | |
for c,w in zip(pattern,words): |
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 Solution: | |
def reconstructQueue(self, people: List[List[int]]) -> List[List[int]]: | |
people=sorted(people, key=lambda x: (-x[0],x[1])) | |
res=[] | |
for p in people: |
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
import random | |
capitals = {'Alabama': 'Montgomery', 'Alaska': 'Juneau', 'Arizona': 'Phoenix', | |
'Arkansas': 'Little Rock', 'California': 'Sacramento', 'Colorado': 'Denver', | |
'Connecticut': 'Hartford', 'Delaware': 'Dover', 'Florida': 'Tallahassee', | |
'Georgia': 'Atlanta', 'Hawaii': 'Honolulu', 'Idaho': 'Boise', 'Illinois': | |
'Springfield', 'Indiana': 'Indianapolis', 'Iowa': 'Des Moines', 'Kansas': | |
'Topeka', 'Kentucky': 'Frankfort', 'Louisiana': 'Baton Rouge', 'Maine': | |
'Augusta', 'Maryland': 'Annapolis', 'Massachusetts': 'Boston', 'Michigan': | |
'Lansing', 'Minnesota': 'Saint Paul', 'Mississippi': 'Jackson', 'Missouri': |
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
import random | |
guess='' | |
while guess not in ('head','tail'): | |
print('Guess the coin Toss ! heads or tails ?!') | |
guess=input() | |
toss=random.randint(0,1) | |
if toss: | |
tt='head' | |
else: |
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
# KIRTI PUROHIT | |
# [email protected] | |
n=int(input()) | |
hate='' | |
for i in range(1,n): | |
if i%2==0: | |
hate+=' I love that' | |
else: | |
hate+=' I hate that' |
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
def car_fueling(dist,miles,n,gas_stations): | |
num_refill, curr_refill, limit = 0,0,miles | |
while limit < dist: | |
# While the destination cannot be reached with current fuel | |
if curr_refill >= n or gas_stations[curr_refill] > limit: | |
# Cannot reach the destination nor the next gas station | |
return -1 | |
# Find the furthest gas station we can reach |
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
data = dict(type = 'choropleth', | |
locations = ['Egypt','Eritrea','Ethiopia', | |
'Central African Republic','Chad','Libya', | |
'South Sudan','Sudan'], | |
locationmode = 'country names', | |
colorscale= 'Portland', | |
text= ['EG','ER','ET','CF','TD','LBY','SDN','SD'], | |
z=[1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0], | |
colorbar = {'title':'Country Colours', 'len':200,'lenmode':'pixels' }) | |
col_map = gobj.Figure(data = [data]) |
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
with open("day12.txt", "r") as file: | |
lines = [(line.rstrip()[0], int(line.rstrip()[1:])) for line in file.readlines()] | |
dirs = ["E", "S", "W", "N", "L", "R", "F"] | |
curr_dir = "E" | |
curr_state = {"E":0, "W":0, "N":0, "S":0} | |
for line in lines: | |
if line[0] == "F": | |
curr_state[curr_dir] += line[1] |