Skip to content

Instantly share code, notes, and snippets.

View kanahaiya's full-sized avatar

Kanahaiya Gupta kanahaiya

View GitHub Profile
package javaaid.coding.interview.preparation;
import java.util.Scanner;
public class TwoPointerTechnique {
// Two Pointer Technique (Opposite-directional)
static int[] twoSum(int[] nums, int target) {
int start = 0;
int end = nums.length - 1;
package javaaid.coding.interview.preparation;
import java.util.Scanner;
public class MaxSumSubArrayOfSizeK {
// brute force solution
// time complexity - O(n*k)
public static int getMaxSumSubArrayOfSizeKM1(int[] A, int k) {
int maxSum = Integer.MIN_VALUE;
package com.javaaid.dp;
import java.util.Scanner;
public class LongestCommonSubsequence {
static Integer dp[][];
static int cache[][];
// Method1()- recursive solution(Top- down approach)
package com.javaaid.dp;
import java.util.Scanner;
public class LongestCommonSubstring {
static Integer dp[][][];
static int cache[][];
// Method1()- recursive solution(Top- down approach)
package com.javaaid.dp;
/**
*
* Problem Statement-
* Given a set S of n items, each with its own value Vi and weight Wi for all 1 <=i <= n
* and a maximum knapsack capacity C, compute the maximum value of the items that you can carry.
* You cannot take fractions of items.
*
* [Tutorial](https://youtu.be/aL6cU5dWmWM)
package com.javaaid.dp;
/**
*
* Problem Statement-
* You are a professional robber planning to rob houses along a street. Each house has a certain amount of money
* stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system
* connected and it will automatically contact the police if two adjacent houses were broken into on the same night.
*
* Given a list of non-negative integers representing the amount of money of each house, determine the maximum amount
package com.javaaid.dp;
/**
*
* Problem Statement-
* A child is climbing up a staircase with n steps and can hop either 1 step or 2 steps at a time.
* Implement a method to count how many possible ways the child can climb up the stairs.
*
*/
import java.util.Scanner;
import java.util.Scanner;
/**
* The {@code FibonacciNumber} class represents a number generator to generate
* Fibonacci Number
*
* @author Kanahaiya Gupta
*/
public class FibonacciNumber {
/**
* @author Kanahaiya Gupta
*
*/
public class LonelyInteger {
static int lonelyinteger(int[] a) {
int result = 0;
for (int i = 0; i < a.length; i++) {
result ^= a[i];
/**
*
* @author Kanahaiya Gupta
*
*/
public class ArraysDS {
// Complete the reverseArray function below.
static int[] reverseArray(int[] a) {
int len = a.length - 1;