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 / 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 / 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 / Problem_statement9.txt
Last active May 10, 2020 17:23
Day9 : 30 Day LeetCode may challenges
In a town, there are N people labelled from 1 to N. There is a rumor that one of these people is secretly the town judge.
If the town judge exists, then:
The town judge trusts nobody.
Everybody (except for the town judge) trusts the town judge.
There is exactly one person that satisfies properties 1 and 2.
You are given trust, an array of pairs trust[i] = [a, b] representing that the person labelled a trusts the person labelled b.
If the town judge exists and can be identified, return the label of the town judge. Otherwise, return -1.
@Gowtham-369
Gowtham-369 / Major_element.cpp
Last active May 6, 2020 13:43
Day5 : 30 Day Leetcode may challenges
class Solution {
public:
int majorityElement(vector<int>& nums) {
/*//Average time complexity is O(n*logn)+1
sort(nums.begin(),nums.end());
int n = nums.size();
//as major element occurs more than [n/2] times,when sorted,compulsorily occurs at mid,as there are n //elements
return nums[n/2];
*/
/*unordered_map<int,int> m;
@Gowtham-369
Gowtham-369 / Number_Complement.cpp
Created May 4, 2020 12:11
Day4 : 30 Day LeetCode may challenges
//overcome runtime error by not doing n=n*2 operation causing overflow
class Solution {
public:
int findComplement(int num) {
/*
5/2 = 2 and 5%2 = 1
2/2 = 1 and 2%2 = 0
1/2 = 0 and 1%2 = 1
*/
/*int sum = 0;
@Gowtham-369
Gowtham-369 / RansomNote1.cpp
Last active May 3, 2020 17:59
Day3: 30 Day LeetCode May Challenges
//TOOK 48 ms
class Solution {
public:
bool canConstruct(string ransomNote, string magazine) {
if(ransomNote.length() == 0 || ransomNote == magazine)
return true;
if(ransomNote.length() > magazine.length())
return false;
unordered_map<char,int> m1;
unordered_map<char,int> m2;
@Gowtham-369
Gowtham-369 / First_Bad_Server.cpp
Created May 1, 2020 12:14
Day 1 : 30 days LeetCode May challenges
// The API isBadVersion is defined for you.
// bool isBadVersion(int version);
class Solution {
public:
int firstBadVersion(int n) {
//searching for first Bad Version(true)
int l = 1;
int r = n;
int mid;