This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| double myPow(double x, int n) { | |
| double ans=1; | |
| long long tempn=n; | |
| if(tempn <0) | |
| tempn=-1*tempn; | |
| while(tempn) | |
| { | |
| if(tempn%2 == 0) | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int maxSubsetSum(vector<int> arr) { | |
| int N = arr.size(); | |
| int dp[N][2]; | |
| if (N == 1) { | |
| return arr[0]; | |
| } | |
| dp[0][0] = 0; | |
| dp[0][1] = arr[0]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| int cache = 0; | |
| public: | |
| ListNode * insert(ListNode *& list, int value){ | |
| ListNode * temp = nullptr; | |
| ListNode * ptr = list; | |
| if(ptr == nullptr){ | |
| temp = new ListNode(value); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int pairs(int k, vector<int> arr) { | |
| int count = 0; | |
| multiset<int> s(arr.begin(), arr.end()); | |
| for(int number : arr) | |
| { | |
| count = count + s.count(number + k); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void whatFlavors(vector<int> cost, int money) { | |
| unordered_map<int, int> table; | |
| vector<int> same_cache; | |
| int index1 = 0; | |
| int index2 = 0; | |
| for(int i = 0; i < cost.size(); i++){ | |
| table[cost[i]] = i; | |
| auto it = table.find(money - cost[i]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pair<bool, tuple<int, int, int>> isTriangle(vector<int> sticks,int it){ | |
| /* triangle inequality theorem */ | |
| /* a + b > c; */ | |
| /* a + c > b */ | |
| /* b + c > a */ | |
| auto it_begin = sticks.begin() + it; | |
| int a = *it_begin; | |
| int b = *(it_begin + 1); | |
| int c = *(it_begin + 2); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int maxMin(int k, vector<int> arr) { | |
| sort(arr.begin(), arr.end()); | |
| int min = INT32_MAX; | |
| for(int i = 0; i + k - 1 < arr.size(); i++){ | |
| int temp = arr[k + i - 1] - arr[i]; | |
| if(temp < min){ | |
| min = temp; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int getMinimumCost(int k, vector<int> c) { | |
| if(k == c.size()){ | |
| return accumulate(c.begin(), c.end(), 0); | |
| } | |
| sort(c.begin(), c.end()); | |
| int cost = 0; | |
| int purchased = 0; | |
| int flowers = c.size() - 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| long arrayManipulation(int n, vector<vector<int>> queries) { | |
| if(n==0 || queries.empty()){ | |
| return -1; | |
| } | |
| vector<long> computation(n); | |
| for (int i = 0; i < queries.size(); i++) { | |
| int a = queries[i][0] - 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int round_num(int v){ | |
| if(v < 38){ | |
| return v; | |
| } | |
| if(v % 5 == 0){ | |
| return v; | |
| } | |
| int num = v; | |
| int temp = num - (num % 5) + 5; | |
| int rem = temp - num; |