Skip to content

Instantly share code, notes, and snippets.

@kodebinary
kodebinary / find-longest-substr-with-unique-chars.cpp
Last active October 23, 2020 11:22
Find the longest substring with given max unique characters. Full article at: https://kodebinary.com/find-the-longest-substring-with-given-max-unique-characters
#include <iostream>
void moveNextChar(string input, int *end) {
char curr = input.at(*end);
do {
*end = *end + 1;
if (*end == input.length()) {
break;
}
char tmp = input.at(*end);
@kodebinary
kodebinary / find-nearest-in-bst.cpp
Last active October 22, 2020 17:17
Find the nearest integer of a give number in binary search tree. Full article: https://kodebinary.com/find-the-nearest-integer-of-a-given-number-in-the-binary-search-tree
#include <iostream>
using namespace std;
struct Node {
int data;
Node *left, *right;
Node(int data) {
this->data = data;
left = NULL;
#include <iostream>
#include <list>
#include <queue>
#include <map>
using namespace std;
// Cloneing a graph.
class GraphNode {
public:
#include <iostream>
using namespace std;
void swap(int &val1, int &val2) {
int temp = val1;
val1 = val2;
val2 = temp;
}
@kodebinary
kodebinary / find-pair-with-given-sum-in-sorted-array.cpp
Last active September 23, 2020 12:53
Find if there exists a pair with a given sum in a sorted array. Full article is at: https://kodebinary.com/find-if-there-exists-a-pair-with-a-given-sum-in-a-sorted-array/
#include <iostream>
using namespace std;
/*
Solution with linear time complexity.
*/
bool findPairSum(int arr[], int size, int sum) {
int start = 0;
int end = size - 1;
#include <iostream>
#include <stack>
using namespace std;
bool isParanthMatch(string inp)
{
stack<char> st;
for (int i = 0; i < inp.length(); i++)
{
#include <iostream>
using namespace std;
int findStartOfRotatedArray(int arr[], int start, int end)
{
int mid = (start + end) / 2;
if (mid == 0)
{
return mid;
#include <iostream>
#include <unordered_map>
using namespace std;
int visibleBoxes(int arr[], int len)
{
unordered_map<int, int> res;
for (int i = 0; i < len; i++)
{
#include <iostream>
#include <string>
using namespace std;
void printCombinations(int val, string res)
{
if (val == 0)
{
cout << res << endl;
#include <iostream>
using namespace std;
struct Node
{
int data;
Node *next;
Node(int data)
{