Skip to content

Instantly share code, notes, and snippets.

View hkasera's full-sized avatar

Harshita hkasera

View GitHub Profile
private boolean sumsToTarget(int[] arr, int k) {
Map<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < nums.length; i++) {
int complement = target - nums[i];
if (map.containsKey(complement)) {
return new int[] { map.get(complement), i };
}
map.put(nums[i], i);
}
throw new IllegalArgumentException("No two sum solution");
private boolean sumsToTarget(int[] arr, int k) {
HashSet values = new HashSet();
for (int i = 0; i < arr.length; i++) {
if (values.contains(k - A[i])) return true;
values.add(A[i]);
}
return false;
}
private boolean sumsToTarget(int[] arr, int k) {
Arrays.sort(arr);
int lhs = 0, rhs = arr.length - 1;
while (lhs < rhs) {
int sum = arr[lhs] + arr[rhs];
if (sum == k)
return true;
else if (sum < k)
lhs++;
else rhs--;
private boolean sumsToTarget(int[] arr, int k) {
Arrays.sort(arr);
for (int i = 0; i < arr.length; i++) {
int siblingIndex = Arrays.binarySearch(arr, k - A[i]);
if (siblingIndex >= 0) {
// Found it!
if (siblingIndex != i || (i > 0 && arr[i-1] == arr[i]) || (i < arr.length - 1 && arr[i+1] == arr[i]))
{ return true; }
}
}
@hkasera
hkasera / TwoSumBruteForce.java
Last active June 1, 2020 23:37
Two Sum problem variations
private boolean sumsToTarget(int[] arr, int k) {
for (int i = 0; i < arr.length; i++) {
for (int j = i + 1; j < arr.length; j++) {
if (arr[i] + arr[j] == k) {
return true;
}
}
}
return false;
}
@hkasera
hkasera / model-1.pkl
Created November 15, 2017 02:22
Model Store
This file has been truncated, but you can view the full file.
ccopy_reg
_reconstructor
p0
(csklearn.pipeline
Pipeline
p1
c__builtin__
object
p2
Ntp3
@hkasera
hkasera / peers.ur
Last active October 19, 2017 20:49
RPC example
table peers : { A : client, B : channel ( string ) , C : string}
PRIMARY KEY A
table random : {C : string}
sequence seq
fun increment a = nextval seq
fun main () =
@hkasera
hkasera / Readme.MD
Last active September 9, 2017 20:43
A node js script to get the top 5 results of given queries in Bing and Google

Installation

$ Install Node.js (Puppeteer requires at least Node v6.4.0)

$ Install puppeteer

$ node query.js > output.txt

@hkasera
hkasera / names.json
Last active September 29, 2020 04:49
Team Names
[
"xterm-inate",
"DEADBEEF",
"hackslash",
"SQL Injectors",
"Hexspeak",
"The Brogrammers",
"GitHub Says What?",
"Bits Please",
"SaaStar",
@hkasera
hkasera / MaximumSubarray.java
Created March 17, 2017 22:25
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.
public class Solution {
public int maxSubArray(int[] nums) {
if(nums.length == 0){
return 0;
}
int[] sum = new int[nums.length];
int[] indices = new int[nums.length];
sum[0] = nums[0];
indices[0] = 0;
for(int i = 1 ; i < nums.length ; ++i){