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 / Shaggy.py
Created July 3, 2020 11:46
The Shaggy Problem in Python !
```
'''
This is a game where you must count to number from 0 to 1000. However, if the number has a 6 in it, or is divisible by 6, you don't say the number. Instead, you say "Shaggy".
Rules:
You can't hard-code the numbers.
The number only has to satisfy at least 1 of the following requirements
Divisible by 6
@Irene-123
Irene-123 / subsets.cpp
Created July 7, 2020 04:06
Subsets Leetcode C++ solution
ITERATIVE SOLUTION
```
class Solution {
public:
vector<vector<int>> subsets(vector<int>& nums) {
vector< vector <int> > res(1,vector<int>());
sort(nums.begin(),nums.end());
for (int i=0;i<int(nums.size());i++){
int n=res.size();
@Irene-123
Irene-123 / subsets.cpp
Created July 7, 2020 04:08
Subsets LeetCode C++ solution
ITERATIVE SOLUTION
```
class Solution {
public:
vector<vector<int>> subsets(vector<int>& nums) {
vector< vector <int> > res(1,vector<int>());
sort(nums.begin(),nums.end());
for (int i=0;i<int(nums.size());i++){
int n=res.size();
for (int j=0;j<n;j++){
@Irene-123
Irene-123 / CAM5.cpp
Created July 12, 2020 15:31
help the Prayatna pr team-SPOJ C++ Solution
```
#include<iostream>
#include<vector>
#include<cstring>
#include<queue>
using namespace std;
int state[1000004];
vector<int>v[100005];
@Irene-123
Irene-123 / symmetric_pairs.py
Created July 13, 2020 03:31
Symmetric pairs in python
```
def symmetric_pairs(d):
for key in d:
val = d[key]
if d[val] == key:
return(val,key)
return -1,-1
@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();
@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 / 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 / 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 / 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):