Skip to content

Instantly share code, notes, and snippets.

View dsapandora's full-sized avatar
🏠
Working from home

Ariel Vernaza dsapandora

🏠
Working from home
View GitHub Profile
@dsapandora
dsapandora / version.cpp
Created April 13, 2020 03:18
Serielize a binary tree
// A C++ program to demonstrate serialization and deserialiation of
// Binary Tree
#include <stdio.h>
#define MARKER -1
/* A binary tree Node has key, pointer to left and right children */
struct Node
{
int key;
struct Node* left, *right;
@dsapandora
dsapandora / version.cpp
Created April 6, 2020 07:49
car chasis factory
// A C++ program to find minimum possible
// time by the car chassis to complete
#include <bits/stdc++.h>
using namespace std;
#define NUM_LINE 2
#define NUM_STATION 4
// Utility function to find minimum of two numbers
int min(int a, int b)
{
@dsapandora
dsapandora / version.cpp
Created April 6, 2020 07:43
edit distancw
// A Dynamic Programming based C++ program to find minimum
// number operations to convert str1 to str2
#include <bits/stdc++.h>
using namespace std;
// Utility function to find the minimum of three numbers
int min(int x, int y, int z)
{
return min(min(x, y), z);
}
@dsapandora
dsapandora / version.cpp
Created April 6, 2020 06:46
Maximum sum such that no two elements are adjacent
#include<stdio.h>
/*Function to return max sum such that no two elements
are adjacent */
int FindMaxSum(int arr[], int n)
{
int incl = arr[0];
int excl = 0;
int excl_new;
int i;
@dsapandora
dsapandora / version.cpp
Created April 6, 2020 06:35
Next Greater Element
// A Stack based C++ program to find next
// greater element for all array elements.
#include <bits/stdc++.h>
using namespace std;
/* prints element and NGE pair for all
elements of arr[] of size n */
void printNGE(int arr[], int n) {
stack < int > s;
@dsapandora
dsapandora / version.cpp
Last active April 6, 2020 06:09
rotate 90 degrees a matrix
// C++ program to rotate a matrix by 90 degrees
#include <bits/stdc++.h>
#define N 4
using namespace std;
void displayMatrix(int mat[N][N]);
// An Inplace function to rotate a N x N matrix
// by 90 degrees in anti-clockwise direction
void rotateMatrix(int mat[][N])
@dsapandora
dsapandora / version.cpp
Created April 6, 2020 05:42
Add two numbers represented by linked lists
// C++ program to add two numbers
// represented by linked list
#include <bits/stdc++.h>
using namespace std;
/* Linked list node */
class Node
{
public:
int data;
@dsapandora
dsapandora / version.cpp
Last active April 6, 2020 05:31
Reverse a Linked List in groups of given size
// CPP program to reverse a linked list
// in groups of given size
#include <bits/stdc++.h>
using namespace std;
/* Link list node */
class Node
{
public:
int data;
@dsapandora
dsapandora / version.cpp
Last active April 6, 2020 05:24
Design and Implement Special Stack Data Structure | Added Space Optimized Version.
#include<iostream>
#include<stdlib.h>
using namespace std;
/* A simple stack class with basic stack funtionalities */
class Stack
{
private:
static const int max = 100;
@dsapandora
dsapandora / version.cpp
Last active April 6, 2020 05:03
Stock Span
// C++ program for a linear time solution for stock
// span problem without using stack
#include <iostream>
#include <stack>
using namespace std;
// An efficient method to calculate stock span values
// implementing the same idea without using stack
void calculateSpan(int A[], int n, int ans[])
{