Skip to content

Instantly share code, notes, and snippets.

View 0001vrn's full-sized avatar
🎯
Focusing

Varun Thakur 0001vrn

🎯
Focusing
View GitHub Profile
@0001vrn
0001vrn / reverseWords.cpp
Created July 31, 2017 08:28
Reverse words in a given string
/*
Given a String of length N reverse the words in it. Words are separated by dots.
By : Varun Thakur
Date : 31/07/2017
*/
#include <bits/stdc++.h>
using namespace std;
void reverse(char *begin, char *end)
@0001vrn
0001vrn / parenthesisChecker.cpp
Created July 31, 2017 08:05
Check for balanced parentheses in an expression
/*
Given an expression string exp , write a program to examine whether
the pairs and the orders of “{“,”}”,”(“,”)”,”[“,”]” are correct in exp.
For example, the program should print true for exp = “[()]{}{[()()]()}”
and false for exp = “[(])”
By : Varun Thakur
Date : 31/07/2017
*/
#include <stack>
@0001vrn
0001vrn / kadaneAlgo.cpp
Created July 31, 2017 07:49
Largest Sum Contiguous Subarray
/*
Write an efficient C program to find the sum of contiguous subarray
within a one-dimensional array of numbers which has the largest sum.
*/
#include <iostream>
using namespace std;
int kadaneAlgo(int arr[],int n)
{
if(n==1)
return arr[0];
@0001vrn
0001vrn / KLargest.cpp
Created July 27, 2017 06:42
K Largest Elements
/*
K Largest Elements
Given an array, print k largest elements from the array.
The output elements should be printed in decreasing order.
By : Varun Thakur
Dated : 27/07/2017
*/
#include <bits/stdc++.h>
using namespace std;
@0001vrn
0001vrn / printParentheses.cpp
Created July 25, 2017 11:52
Print all combinations of balanced parentheses
#include <iostream>
using namespace std;
#define MAX_SIZE 100
void printParentheses(int n);
void _printParentheses(int pos, int n, int open, int close);
void printParentheses(int n)
{
if(n>0)
_printParentheses(0,n,0,0);
@0001vrn
0001vrn / pascal.cpp
Created July 18, 2017 12:48
Pascal’s triangle is a triangular array of the binomial coefficients. Write a function that takes an integer value n as input and prints first n lines of the Pascal’s triangle. Following are the first 6 rows of Pascal’s Triangle.
/*
Pascal’s triangle is a triangular array of the binomial coefficients.
Write a function that takes an integer value n as input and prints
first n lines of the Pascal’s triangle. Following are the first 6
rows of Pascal’s Triangle.
*/
#include <iostream>
using namespace std;
int binomialCoefficient(int, int);
@0001vrn
0001vrn / rand_string_gen.cpp
Created July 18, 2017 02:00
random string generator
#include <iostream>
using namespace std;
static char *rand_string(char *str, size_t size)
{
const char charset[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJK...";
if (size) {
--size;
for (size_t n = 0; n < size; n++) {
int key = rand() % (int) (sizeof charset - 1);
str[n] = charset[key];
@0001vrn
0001vrn / RunLengthCoding.java
Created July 1, 2017 03:41
Run Length Coding
import java.util.*;
import java.lang.*;
import java.io.*;
class RunLengthCoding
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
#include <iostream>
using namespace std;
void pattern1(int n){
int cnt=1;
for(int i=0; i<2*n-1; i++){
for(int j=0; j<(abs(n-1-i)); j++)cout<<" ";
for(int j=0; j<2*(n-abs(n-1-i))-1; j++)cout<<cnt++;
cout<<endl;
}
package com.company;
import java.util.Arrays;
import java.util.Scanner;
import static java.util.Arrays.binarySearch;
public class EXTRAN {