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
# --------------------------------------------------------------------------- | |
# | |
# Description: This file holds all my BASH configurations and aliases | |
# | |
# Sections: | |
# 1. Environment Configuration | |
# 2. Make Terminal Better (remapping defaults and adding functionality) | |
# 3. File and Folder Management | |
# 4. Searching | |
# 5. Process Management |
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
/* | |
Given a sorted array of integers, find the starting and ending position of a given target value. | |
Your algorithm’s runtime complexity must be in the order of O(log n). | |
If the target is not found in the array, return [-1, -1]. | |
Example: | |
Given [5, 7, 7, 8, 8, 10] |
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
/* | |
Write an efficient algorithm that searches for a value in an m x n matrix. | |
This matrix has the following properties: | |
Integers in each row are sorted from left to right. | |
The first integer of each row is greater than or equal to the last integer of the previous row. | |
Example: | |
Consider the following matrix: | |
[ | |
[1, 3, 5, 7], | |
[10, 11, 16, 20], |
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
/*Rearrange a given array so that Arr[i] becomes Arr[Arr[i]] with O(1) extra space. | |
Example: | |
Input : [1, 0] | |
Return : [0, 1] | |
Lets say N = size of the array. Then, following holds true : | |
* All elements in the array are in the range [0, N-1] | |
* N * N does not overflow for a signed integer | |
https://www.interviewbit.com/problems/rearrange-array/ */ | |
void Solution::arrange(vector<int> &A) { | |
auto n = A.size(); |
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 Solution::titleToNumber(string A) { | |
auto n = A.length(); | |
int value = 0; | |
for (auto i=0; i<n; ++i) | |
{ | |
value += pow(26, i)*(A[n-(i+1)] - 'A' + 1); | |
} | |
return 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
bool Solution::isPower(int A) { | |
if (A<2) | |
return true; | |
for (auto i = 2; i<=sqrt(A); ++i) | |
{ | |
for (auto j = 2; j<=32; ++j) | |
{ | |
if(pow(i, j)==A) | |
return true; |
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
bool isPrime(int n) | |
{ | |
for(int i=2; i*i<=n; ++i) | |
{ | |
if(n%i==0) | |
return false; | |
} | |
return true; | |
} |
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 Solution::gcd(int A, int B) { | |
//Euclid's algorithm | |
while(B!=0) | |
{ | |
int r = A%B; | |
A = B; | |
B = r; | |
} | |
return A; | |
} |
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
string Solution::findDigitsInBinary(int A) { | |
int r; | |
string result; | |
if(A==0) | |
return "0"; //prev used result += to_string(0); return result; | |
while(A>0) | |
{ | |
r = A%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 Solution::isPrime(int A) { | |
if (A<2) | |
return 0; | |
for(auto i=2; i<=sqrt(A); ++i) | |
{ | |
if(A%i==0) | |
return 0; | |
} | |
return 1; | |
} |
NewerOlder