Skip to content

Instantly share code, notes, and snippets.

View sangrambankar's full-sized avatar

Sangram Bankar sangrambankar

  • Fremont, CA
View GitHub Profile
public class ColumnNumberToExcelName {
public String convertToTitle(int n) {
String[] arrayAlpha = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
String ans="";
if(n<=26){
ans = arrayAlpha[n-1].toUpperCase();
}else{
int remaintoN = n%26;
int multiple = n/26;
// Java program to reverse an array
import java.io.*;
class ReverseArray {
/* Function to reverse arr[] from start to end*/
static void rvereseArray(int arr[], int start, int end)
{
int temp;
if (start >= end)
@sangrambankar
sangrambankar / ProductSubarray
Created October 20, 2016 05:16
Largest product in array
// Java program to find maximum product subarray
import java.io.*;
class ProductSubarray {
// Utility functions to get minimum of two integers
static int min (int x, int y) {return x < y? x : y; }
// Utility functions to get maximum of two integers
static int max (int x, int y) {return x > y? x : y; }
@sangrambankar
sangrambankar / MaximumSumPath.java
Created October 20, 2016 05:11
Max sum path in two arrays
class MaximumSumPath
{
// Utility function to find maximum of two integers
int max(int x, int y)
{
return (x > y) ? x : y;
}
// This function returns the sum of elements on maximum path
// from beginning to end
@sangrambankar
sangrambankar / Remove Duplicates from Sorted Array.java
Created October 20, 2016 05:07 — forked from guolinaileen/Remove Duplicates from Sorted Array.java
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do this in place with constant memory. For example, Given input array A = [1,1,2], Your function should return length = 2, and A is now [1,2].
public class Solution {
public int removeDuplicates(int[] A) {
int length=A.length;
if(length==0 || length==1) return length;
int i=1;
for(int j=1; j<length; j++)
{
if(A[j]!=A[j-1])
{
A[i]=A[j];