Skip to content

Instantly share code, notes, and snippets.

## SHELL SCRIPT
## Mainly Questions from HackerRank
##
# Print anything
$ echo "HELLO"
# time when i logged in ?
$ who am i
o/p : username terminal_id time
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;
}
/**
* 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 {
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++){
class Stack {
public:
queue<int> q;
int size;
Stack(){
size=0;
}
// Push element x onto stack.
Algorithm ::
Variables :
L = 0
R = 0
currentSum = 0
maxSum = 0 // keep track of max sum
// max sum sub matrix indexes
left = 0
right = 0
/*
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;
#include<bits/stdc++.h>
using namespace std;
struct Node {
char data;
Node *left,*right,*eq;
bool isEnd;
Node(char c){
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;
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