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
| #include <iostream> | |
| int at(int* arr, int n, int k, int m) { | |
| return arr[((m + (n - (k % n))) % n)]; | |
| } | |
| int rotated_binary_search(int* arr, int n, int k, int key) { | |
| int low = 0, high = n-1, mid, v; | |
| while (low <= high) { |
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
| #include <iostream> | |
| using namespace std; | |
| // returns the element at index m in arr after k rotations | |
| int at(int* arr, int n, int k, int m) { | |
| return arr[((m + (n - (k % n))) % n)]; | |
| } | |
| int main() { | |
| int n, k, q, i, j, m; |
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
| #include<iostream> | |
| struct node{ | |
| int data; | |
| node* next; | |
| }; | |
| node* NewNode(int data){ | |
| node* n=new node; | |
| n->data=data; |
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
| #include <cstring> | |
| using namespace std; | |
| void downup(const char str[]) { | |
| int n = strlen(str); | |
| int i, j; | |
| for (i = 0; i < n; ++i) { | |
| for (j = 0; j < n-i; ++j) | |
| cout << str[j]; | |
| cout << '\n'; |
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
| // NumberGuessing.cpp : Defines the entry point for the console application. | |
| // | |
| #include "stdafx.h" | |
| #include <iostream> | |
| #include <ctime> | |
| #include <vector> | |
| #include <numeric> | |
| #include <limits> | |
| #include <string> |
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
| struct ListNode { | |
| int val; | |
| struct ListNode* next; | |
| ListNode(int val) : val(val), next(0) {} | |
| }; | |
| struct ListNode* newNode(int data) { | |
| return new struct ListNode(data); | |
| } |
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
| #include <iostream> | |
| #include <vector> | |
| using namespace std; | |
| inline int max(int a, int b) { | |
| return a > b ? a : b; | |
| } | |
| int trunc(int v) { | |
| if (abs(v) == 1) return abs(v); |
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
| #include <iostream> | |
| #include <vector> | |
| using std::max; | |
| // Let A be an array of length N | |
| // Let M(i) be the largest contiguous subsequence ending at index i | |
| // M(0) = 1 | |
| // M(i) = max(M(i),M(j)+1) for j<i and A[j]<=A[i] | |
| int maxSubArray(int A[], int N) { |
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
| #include <algorithm> | |
| #include <streambuf> | |
| #include <iostream> | |
| #include <fstream> | |
| #include <stdexcept> | |
| #include <utility> | |
| #include <string> | |
| #include <vector> | |
| #include <cctype> | |
| #include <memory> |
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
| #include <iostream> | |
| #include <string> | |
| #include <sstream> | |
| std::string UnaryToBinary(std::string str) { | |
| std::string binary; | |
| binary.reserve(30); | |
| char flag; | |
| for (std::stringstream ss(str); ss >> str; ) { |