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
## SHELL SCRIPT | |
## Mainly Questions from HackerRank | |
## | |
# Print anything | |
$ echo "HELLO" | |
# time when i logged in ? | |
$ who am i | |
o/p : username terminal_id time |
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 { | |
public: | |
int getMoneyAmount(int n) { | |
int dp[n+1][n+1]; | |
memset(dp,0,sizeof(INT_MAX)); | |
for(int i=1;i<=n;i++){ | |
dp[i][i]=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
/** | |
* Definition for a binary tree node. | |
* struct TreeNode { | |
* int val; | |
* TreeNode *left; | |
* TreeNode *right; | |
* TreeNode(int x) : val(x), left(NULL), right(NULL) {} | |
* }; | |
*/ | |
class Codec { |
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 { | |
public: | |
int maxCoins(vector<int>& v) { | |
int n=v.size(); | |
if(n==0) return 0; | |
int dp[n][n]; | |
for(int len=1;len<=n;len++) { | |
for(int left=0;left+len-1<n;left++){ |
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 Stack { | |
public: | |
queue<int> q; | |
int size; | |
Stack(){ | |
size=0; | |
} | |
// Push element x onto stack. |
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
Algorithm :: | |
Variables : | |
L = 0 | |
R = 0 | |
currentSum = 0 | |
maxSum = 0 // keep track of max sum | |
// max sum sub matrix indexes | |
left = 0 | |
right = 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
/* | |
matrix chain Multiplication | |
1 2 3 | |
[2 , 3] [3 , 4] [4 , 5] | |
p0 p1 p1 p2 p2 p3 | |
*/ | |
#include<bits/stdc++.h> | |
using namespace std; |
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<bits/stdc++.h> | |
using namespace std; | |
struct Node { | |
char data; | |
Node *left,*right,*eq; | |
bool isEnd; | |
Node(char c){ |
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 { | |
public: | |
int calculate(int a,int b,char c){ | |
switch(c) { | |
case '+': return a+b; | |
case '-': return a-b; | |
case '*': return a*b; | |
case '/': | |
if(b!=0) return a/b; | |
else return 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
1. return statement can't be used with ternary operator. | |
2. max length of variable is 31 characters. | |
3. sizeof((int)(double)(char)i) is 4 bytes. Because at the end it is type casted into int. | |
4. Modulo operator gives remainder after dividing numerator with denominator and result has sign of numerator. | |
10 % 3 = 1 | |
10 % -3 = 1 | |
-10 % 3 = -1 |