Skip to content

Instantly share code, notes, and snippets.

View 0001vrn's full-sized avatar
🎯
Focusing

Varun Thakur 0001vrn

🎯
Focusing
View GitHub Profile
#include <iostream>
#include <stack>
#include <queue>
#include <climits>
using namespace std;
class BTNode
{
public:
int data;
@0001vrn
0001vrn / Kswap.cpp
Last active July 16, 2016 12:25
Given a number M (N-digit integer) and K-swap operations(a swap operation can swap 2 digits), devise an algorithm to get the maximum possible integer? #Google #Interview #Question
#include <iostream>
using namespace std;
/*
Approach - Selection sort descending order
*/
int Kswap(int num, int k)
{
string arr = to_string(num);
@0001vrn
0001vrn / DistinctSum.cpp
Created July 30, 2016 10:11
Given N and N elements Find the number of distinct sums.
#include <iostream>
#include <unordered_set>
using namespace std;
int main() {
// your code goes here
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
@0001vrn
0001vrn / DistinctSum.java
Created July 30, 2016 10:16
Given N and N elements Find the number of distinct sums
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
@0001vrn
0001vrn / DFS.cpp
Created July 30, 2016 17:12
Depth First Traversal (or Search) for a graph is similar to Depth First Traversal of a tree. The only catch here is, unlike trees, graphs may contain cycles, so we may come to the same node again. To avoid processing a node more than once, we use a boolean visited array.
#include <iostream>
#include <list>
using namespace std;
class Graph{
int V;
list<int> *adj;
void DFSUtil(int v,bool visited[]);
public:
Graph(int V){
#include <iostream>
#include <list>
#include <stack>
using namespace std;
class Graph{
int V;
list<int> *adj;
void DFSUtil(int v,bool visited[],stack<int> &s);
public:
@0001vrn
0001vrn / countingSort.cpp
Created August 16, 2016 08:17
C++ program to implement Counting Sort
#include <iostream>
using namespace std;
void countingSort(int arr[],int n,int RANGE){
int count[RANGE]={0};
int i;
int out[n];
for(i=0;i<n;i++)
@0001vrn
0001vrn / StackUsingQueues.cpp
Created August 16, 2016 11:56
Implement Stack using Queues
#include <iostream>
#include <queue>
using namespace std;
queue<int> q1,q2;
void ppush(int x){
q1.push(x);
}
int pop(){
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{