Skip to content

Instantly share code, notes, and snippets.

View Gowtham-369's full-sized avatar
💭
Chasing Good Dreams

Gowtham Reddy Uppunuri Gowtham-369

💭
Chasing Good Dreams
View GitHub Profile
@Gowtham-369
Gowtham-369 / K_nearest_points_to_origin.cpp
Created May 30, 2020 11:09
Day 30 : LeetCode 30 Day May Challenges
//always STL generally takes extra space than arrays
//better use them
class Solution {
public:
int distance(vector<int>& v){
return v[0]*v[0]+v[1]*v[1];
}
vector<vector<int>> kClosest(vector<vector<int>>& points, int K) {
//for all points in points ,calculate distances and store it in array
//sort it and get distance of kth nearest point
@Gowtham-369
Gowtham-369 / counting_bits.cpp
Last active May 28, 2020 10:31
Day 28 : LeetCode 30 Day May Challenges
class Solution {
public:
//sizeof(int) = 32 bits/4 bytes
//what i observed is
//0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ... indices
//0 1 [1 2][1 2, 2 3] [1 2 2 3, 2 3 3 4] [1 2 2 3 2 3 3 4, 2 3 3 4 3 4 4 5]
vector<int> countBits(int num) {
if(num == 0)
return {0};
else if(num == 1)
@Gowtham-369
Gowtham-369 / Possible_bipartition.cpp
Last active January 4, 2021 05:31
Day 27 : LeetCode 30 Day May Challenges
class Solution {
public:
set <int> groups[2];
bool dfs(int node, vector <int> graph[], int x){
int aux = 1 - x;
if(groups[aux].count(node)) return false;
groups[x].insert(node);
for(int i = 0; i < graph[node].size(); i++){
int u = graph[node][i];
if(!groups[aux].count(u) && !dfs(u, graph, aux)) return false;
@Gowtham-369
Gowtham-369 / Contigious_Binary_array.cpp
Last active May 27, 2020 10:55
Day 26: LeetCode 30 Day May Challenges
class Solution {
public:
/*bool Areequal(string s){
int z=0,v=0;
for(auto x : s){
if(x == '0')
z++;
else
v++;
}
@Gowtham-369
Gowtham-369 / Interaval_list_Intersections.cpp
Last active May 23, 2020 11:52
Day 22:LeetCode 30 Day May Challenges
class Solution {
public:
vector<vector<int>> intervalIntersection(vector<vector<int>>& A, vector<vector<int>>& B) {
//already sorted intervals
//vector<pair<int,int>> u;
//vector<pair<int,int>> v;
vector<vector<int>> ans;
//have to handle empty cases
int m = A.size();
//for(int i=0; i<m; i++){
@Gowtham-369
Gowtham-369 / Problem_statement21.txt
Last active May 22, 2020 12:31
Day 21:LeetCode 30 Day May Challenges
Given a string, sort it in decreasing order based on the frequency of characters.
Example 1:
Input:
"tree"
Output:
"eert"
@Gowtham-369
Gowtham-369 / Count_square_submatrices_with_all_ones.cpp
Created May 21, 2020 12:31
Day 20:Leetcode 30 Day may challenges
class Solution {
public:
int solve(vector<vector<int>>& matrix){
//copy first col and row of matrix,because we need them.
//start from i=j=1,
//if(S[i][j] == 1) S[i][j] = min(S[i][j-1],S[i-1][j],S[i-1][j-1])+1;
//else S[i][j] = 0
//vector<int> a(n,0);
//vector<vector<int>> S(m,a);
int m = matrix.size();
@Gowtham-369
Gowtham-369 / Kth_smallest_element_in_BST.cpp
Last active May 20, 2020 12:58
Day 19:LeetCode 30 Day may challenges
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
* };
@Gowtham-369
Gowtham-369 / Permutation_in_a_string.cpp
Created May 18, 2020 08:00
Day 17;LeetCode 30 Day may challenges
class Solution {
public:
bool check_anagrams(vector<int>& a,vector<int>& b){
if(a == b)
return true;
else
return false;
}
bool solve(string&s ,string& p){
int m = p.size();
@Gowtham-369
Gowtham-369 / Odd_Even_Linked_list.cpp
Created May 16, 2020 17:46
Day 15:LeetCode 30 Day May challenges
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode() : val(0), next(nullptr) {}
* ListNode(int x) : val(x), next(nullptr) {}
* ListNode(int x, ListNode *next) : val(x), next(next) {}
* };
*/