Skip to content

Instantly share code, notes, and snippets.

View Irene-123's full-sized avatar
🎯
Focusing

kirti purohit Irene-123

🎯
Focusing
View GitHub Profile
@Irene-123
Irene-123 / Teacher's quiz.py
Created September 27, 2020 09:42
Automate the boring stuff -generate random quiz project
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':
@Irene-123
Irene-123 / QueueReconstructionbyHeight.py
Created August 14, 2020 03:50
406. Queue Reconstruction by Height LeetCode Python Solution
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:
@Irene-123
Irene-123 / word_pattern.py
Created August 13, 2020 02:45
Word Pattern-LeetCode Python Solution
#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):
@Irene-123
Irene-123 / Monotone Increasing Digits.py
Created August 10, 2020 04:08
Monotone Increasing Digits
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]:
@Irene-123
Irene-123 / Josephus.cpp
Created July 21, 2020 15:05
THe Josephus Problem in C++
/* THE FOLLOWING CODE HAS BEEN COMPILED IN DOS TURBO C++
*/
#include<iostream.h>
#include<conio.h>
int highestPowerof2(int n)
{
int res = 0;
@Irene-123
Irene-123 / Leaders_in_array.py
Created July 21, 2020 14:44
Leaders In an Array Python
'''
Problem: You are given an array. You have to write a program that will print all the leaders in the array. An element is leader if it is greater than all the elements to its right side. And the rightmost element is always a leader.
For example array {6, 7, 4, 3, 5, 2}, leaders are 7, 5 and 2.
'''
def Leaders(nums,n):
res=[]
max_ele=nums[-1]
res.append(max_ele)
for i in range (n-2,-1,-1):
@Irene-123
Irene-123 / Destination_City.py
Created July 20, 2020 15:19
Destination City-LeetCode Python solution
class Solution:
def destCity(self, paths: List[List[str]]) -> str:
seen=set(p[0] for p in paths)
for city in paths:
if city[1] not in seen:
return city[1]
@Irene-123
Irene-123 / Destination_City.cpp
Created July 20, 2020 15:13
Destination City-LeetCode
class Solution {
public:
string destCity(vector<vector<string>>& paths) {
unordered_map<string,int> degreeMap; //create an unordered map
for(auto& e: paths){ //iterator e for paths' vector
degreeMap[e[0]] += 1; //for every city position increase the counter
degreeMap[e[1]] += 0; //dont increase the counter for destination city
}
for (auto& [k, v]: degreeMap)
@Irene-123
Irene-123 / K_strongest.py
Last active July 20, 2020 11:41
K strongest Values in an Array
'''
Given an array of integers arr and an integer k.
A value arr[i] is said to be stronger than a value arr[j] if |arr[i] - m| > |arr[j] - m|
where m is the median of the array.
If |arr[i] - m| == |arr[j] - m|, then arr[i] is said to be stronger than arr[j] if arr[i] > arr[j].
Return a list of the strongest k values in the array. return the answer in any arbitrary order.
@Irene-123
Irene-123 / Russian Dolls.cpp
Created July 17, 2020 11:38
Russian dolls Envelopes -LeetCode C++
//SOLUTION 1 - DP O(N<sup>2</sup>)
class Solution {
public:
static bool compare (vector<int>& i, vector<int>& j) {
return i[0]*i[1] <j[0]*j[1];
}
int maxEnvelopes(vector<vector<int>>& envelopes) {
sort(envelopes.begin(), envelopes.end(), compare);
int N = envelopes.size();