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 / 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;
@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 / 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 / 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 / check_if_a_straight_line.cpp
Created May 8, 2020 12:43
Day7 : 30 Day LeetCode May Challenges
class Solution {
public:
/*double calculate_slope(int x_1,int x_2,int y_1,int y_2){
return (double)(y_2 -y_1)/(x_2 - x_1);
}
*/
bool checkStraightLine(vector<vector<int>>& coordinates) {
int n = coordinates.size();
if(n == 2)
return true;
@Gowtham-369
Gowtham-369 / Problem_Statement.txt
Last active May 9, 2020 07:03
IARCS OPC Judge Problems » Sorting Rows of Numbers
You will be given several lines of input where each line contains a sequence of positive integers.
Your task is to sort these lines in lexicographic order.
Lexicographic order is the order in which words are listed in the dictionary.
The ordering is determined by the left most element (in this case the left most integer on each line)
and if the left most elements are equal then by the second element from the left,
if the left most and the second element from the left are equal then by the third element from the left and so on.
For example, when the lines
14 38 11 89
@Gowtham-369
Gowtham-369 / Valid_perfect_square.cpp
Created May 9, 2020 15:01
Day8 : 30 Day LeetCode May challenges
class Solution {
public:
bool isPerfectSquare(int num) {
/*int n = sqrt(num);
for(int i=1; i<=n; i++){
if(i*i == num)
return true;
}
return false;
*/
@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 / Problem_statement11.txt
Created May 12, 2020 11:29
Day 11 : 30 Day LeetCode May Challenges
You are given a sorted array consisting of only integers where every element appears exactly twice, except for one element which appears exactly once. Find this single element that appears only once.
Example 1:
Input: [1,1,2,3,3,4,4,8,8]
Output: 2
Example 2:
@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) {}
* };
*/