Skip to content

Instantly share code, notes, and snippets.

#include <iostream>
using namespace std;
#define MAX_CHARS 127
void removeDupChars(char inp[], int len)
{
int dp[MAX_CHARS];
int cnt = 0;
@kodebinary
kodebinary / remove-alternate-duplicate-chars.cpp
Last active July 12, 2020 14:41
Remove alternate duplicate characters from the input string in-place. Full article is at: https://kodebinary.com/remove-alternate-duplicate-characters-in-a-sentence-in-place
#include <iostream>
using namespace std;
#define MAX_CHARS 127
void removeAlternateDups(char inp[], int len)
{
// Keep an array of 127 size to store character occurrence.
// As the size is constant, we can consider this as constant space.
#include <iostream>
using namespace std;
void swap(char *a, char *b)
{
char tmp = *a;
*a = *b;
*b = tmp;
}
@kodebinary
kodebinary / two-nodes-with-input-sum-in-bst.cpp
Last active July 10, 2020 15:33
Find two nodes with a given input sum in a binary search tree. Full article is at: https://kodebinary.com/find-two-nodes-with-a-given-sum-in-a-binary-search-tree
#include <iostream>
#include <unordered_map>
using namespace std;
struct Node
{
int data;
Node *left;
Node *right;
@kodebinary
kodebinary / queue-using-two-stacks.cpp
Created July 5, 2020 17:20
Implement Queue using two stacks. Full article is at: https://kodebinary.com/queue-using-two-stacks
#include <iostream>
#include <stack>
using namespace std;
class Queue {
stack<int> st;
public:
Queue() {};
~Queue() {}
#include <iostream>
using namespace std;
// Common approach using a "temp" variable.
void swap(int &a, int &b) {
int temp = a;
a = b;
b = temp;
}
#include <iostream>
using namespace std;
int findStartOfOnes(int inp[], int start, int end) {
if(start <= end) {
int mid = (start + end) / 2;
if(inp[mid] == 1 && inp[mid-1] == 0) {
return mid;
}
#include <iostream>
using namespace std;
void swap(int *a, int *b) {
int tmp = *a;
*a = *b;
*b = tmp;
}
#include <iostream>
#define MAX_CHAR 255
using namespace std;
bool checkAnagrams(string str1, string str2)
{
int arr[MAX_CHAR] = {0};
if (str1.length() != str2.length())
{
return false;
#include <iostream>
using namespace std;
struct Node
{
int data;
struct Node *next;
Node(int data)
{