Skip to content

Instantly share code, notes, and snippets.

View naveenwashere's full-sized avatar
🎯
Focusing

Naveen Kumar K naveenwashere

🎯
Focusing
View GitHub Profile
package com.datastructures;
public class BinarySearchTreeDS<Key extends Comparable<Key>, Value> {
//My node of a BST
private class Node
{
Key key;
Value value;
Node left, right;
public Node(Key key, Value value) {
package com.datastructures;
public class BinaryHeap {
//This is an implementation of Binary Heap using an array.
//The Binary Heap is represented as a Tree. The Root of the tree is the 1st index in the array. Lets call that 'k'.
//The left and right child of the tree are computed using the formula 2k and 2k+1
//If you want to find the index of the parent from, from the node you're currently in, then you can use the formula k/2.
//This is how we shall be traversing the tree and also this is the reason we keep the root of the tree at the 1st index of the array and not the 0th.
//Property of the Binary Heap Tree: The element in the root always has to be greater than both its children/child elements
@naveenwashere
naveenwashere / QuickSortingAlgo.java
Last active December 17, 2015 16:18
Updating the correct code to sort array even with duplicate elements. The problem was in the way I was incrementing and decrementing the i and j pointers. In my previous code (if you see the previous revisions), I was doing the increment and decrement after the I check for the value and then performing the operation inside the while loop. In the…
package com.algorithms;
import java.util.Random;
/**
* Quicksort is popular because it is not difficult to implement, works well for
* a variety of different kinds of input data, and is substantially faster than
* any other sorting method in typical applications. It is in-place (uses only a
* small auxiliary stack), requires time proportional to N log N on the average
* to sort N items, and has an extremely short inner loop. The basic algorithm:
package com.algorithms;
import java.util.Arrays;
import java.util.Scanner;
public class BinarySearch {
public boolean search(int low, int hi, int[] a, int searchFor)
{
int mid = (hi + low)/2;
if(a[mid] == searchFor) return true;
@naveenwashere
naveenwashere / Decompresser.java
Created May 29, 2013 17:47
This is a simple class that decompresses any known archive file. You just have to provide the path of the file to decompress. I wrote this code as I saw a post in Google+ who wanted to know how to decompress a file. So I thought, "well, lets try to write one!". Though its a small code, I confess, I had to struggle a bit. Happy Coding.
package com.gplus;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.Scanner;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
@naveenwashere
naveenwashere / RotateMatrixByOneEightyDegree
Created January 8, 2014 16:49
Rotate a Matrix by +180 degrees.
package com.interview.coding.crack;
public class RotateMatrixByOneEightyDegree {
public void rotateByOneEightyDegree(int[][] array, int m, int n)
{
for(int i = 0; i < ((m/2) + (m%2)); i++)
{
int first = i;
int last = n - 1;
@naveenwashere
naveenwashere / FindingIfSubstring.java
Created January 13, 2014 18:21
Assume you have a method isSubstring which checks if one word is a substring of another. Given two string s1 and s2, write code to check if s2 is a roatation of sq using only one call ot isSubstring (eg., "waterbottle" is a rotation of "erbottlewat").
package com.interview.coding.crack;
public class FindingIfSubstring {
public boolean isSubstring(char a[], char b[])
{
int joint = 0;
int indexer = 0;
boolean flag = false;
if(a.length != b.length)
@naveenwashere
naveenwashere / introrx.md
Created May 19, 2017 07:50 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
@naveenwashere
naveenwashere / gist:5a5117e4326165d4524f
Created June 14, 2015 15:22
Fiberlink online coding challenge - Program | Railway ticket counter and revenue problem
import java.util.Arrays;
import java.util.Scanner;
public class RailwayTickets {
int numOfTickets, ticketsToSell;
int[] ticketsPerBooth;
public RailwayTickets(int numOfTickets, int ticketsToSell, int[] ticketsPerBooth)
{
this.numOfTickets = numOfTickets;
@naveenwashere
naveenwashere / ListMax.java
Created July 4, 2015 13:20
List Max. Hackerrank question for one of the companies.
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
/*
* HACKERRANK INTERVIEW QUESTION
*
* You are given a list of size N, initialized with zeroes. You have to perform M queries on the list and output the
* maximum of final values of all the N elements in the list. For every query, you are given three integers a, b and k and