Skip to content

Instantly share code, notes, and snippets.

#include <iostream>
#include <unordered_map>
using namespace std;
struct Node
{
int data;
struct Node *next;
Node(int data)
#include <iostream>
using namespace std;
struct Node
{
int data;
struct Node *left;
struct Node *right;
};
@kodebinary
kodebinary / min-cost-to-reach-end-of-array.cpp
Created June 13, 2020 08:20
Minimum cost to reach end of array with given maximum jump K (recursion & dynamic programming approach), Full article is at: https://kodebinary.com/minimum-cost-to-reach-the-end-of-the-array-using-recursion-and-dynamic-programming
#include <iostream>
using namespace std;
int minCostToEndRecursion(int arr[], int size, int k)
{
int result = INT_MAX;
if (size < 0)
{
return 0;
#include <iostream>
#include <list>
using namespace std;
class Vertex {
public:
int data;
list<pair<int, Vertex> > edges;
Vertex() {
#include <iostream>
using namespace std;
bool isPalindromIterative(char *inp, int len)
{
for (int i = 0; i < len / 2; i++)
{
if (inp[i] != inp[len - 1 - i])
{
@kodebinary
kodebinary / approaches-to-reverse-a-string.cpp
Last active June 7, 2020 11:46
Reverse a string with different approaches. Full article is at: https://kodebinary.com/different-methods-to-reverse-a-string
#include <stdio.h>
#include <stdlib.h>
#include <stack>
void swap(char *a, char *b)
{
char temp = *a;
*a = *b;
*b = temp;
}
#include <iostream>
using namespace std;
int max(int a, int b, int c)
{
return max(a, max(b, c));
}
int longestPalindromSubseqRecur(char arr[], int len, int start, int end)
#include <iostream>
using namespace std;
void printSubsequences(string inp, string subs)
{
if (inp.length() == 0)
{
cout << subs << endl;
return;
#include <iostream>
using namespace std;
int longestCommonSubseqRec(char arr1[], char arr2[], int len1, int len2)
{
if (len1 == 0 || len2 == 0)
{
return 0;
}
#include <iostream>
using namespace std;
int countSubsetSumEqualsGivenSumRec(int arr[], int size, int sum)
{
if (sum < 0 || size < -1)
{
return 0;
}