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 / 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 / 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 / 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 / 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 / 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 / temperatures.py
Created June 25, 2020 04:58
CodinGame Temperatures Puzzle
```python3
import sys
import math
from functools import reduce
# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.
n = int(input())
if n==0:
print(0)
@Irene-123
Irene-123 / Climbing_stairs.py
Created June 24, 2020 08:45
70. Climbing Stairs Leetcode Python solution
This problem has typically 3-4 approaches .I'm gonna show two of them here .
1. DYANAMIC PROGRAMMING APPROACH .
```python3
class Solution:
def climbStairs(self, n: int) -> int:
if n==0:
return 0
if n==1:
return 1
dp=[0]*(n+1)
```python3
class Solution:
def multiply(self, num1: str, num2: str) -> str:
def mul(num1, num2):
if len(num1) == 1 or len(num2) == 1:
return int(num1) * int(num2)
m = min(len(num1), len(num2)) // 2
a, b = num1[:len(num1) - m], num1[len(num1) - m:]
c, d = num2[:len(num2) - m], num2[len(num2) - m:]
z0 = mul(b, d)
@Irene-123
Irene-123 / estimate_pi.py
Last active January 20, 2021 07:33
Monte Carlo Estimation of Pi in python
PROBLEM STATEMENT- You have a cicle of radius 1 embedded in the square . There are some random points everywhere ,some inside the circle
and some outside which contribute to the points in square
**************DISPLAY IS PROVIDED BELOW IN THE COMMENT SECTION********
ALGORITHM- 1. Generate some random numbers between 0 and 1
2. check the distance of the point from the origin
3. if x**2 + y**2 =distance <1 then the point lies inside the circle
4. Increment nums_points_circle
5. Increment nums_total_points .
@Irene-123
Irene-123 / Dutch_flag_prblm_on_leetcode.py
Created June 21, 2020 07:13
Leetcode solution-Sort Colors .Dutch National Flag problem
```python3
#https://en.wikipedia.org/wiki/Dutch_national_flag_problem
#https://leetcode.com/problems/sort-colors/
def sortColors(self, nums):
red, white, blue = 0, 0, len(nums)-1
while white <= blue:
if nums[white] == 0:
nums[red], nums[white] = nums[white], nums[red]
white += 1