Skip to content

Instantly share code, notes, and snippets.

View gauravkr0071's full-sized avatar
❤️

Gaurav gauravkr0071

❤️
View GitHub Profile
/*
454. 4Sum II
Medium
2280
85
Add to List
/*
Given an array nums of n integers, return an array of all the unique quadruplets [nums[a], nums[b], nums[c], nums[d]] such that:
0 <= a, b, c, d < n
a, b, c, and d are distinct.
nums[a] + nums[b] + nums[c] + nums[d] == target
You may return the answer in any order.
@gauravkr0071
gauravkr0071 / Two Sum II - Input array is sorted.cpp
Created August 12, 2021 18:10
Two Sum II - Input array is sorted
/*
167. Two Sum II - Input array is sorted
Easy
Given an array of integers numbers that is already sorted in non-decreasing order,
find two numbers such that they add up to a specific target number.
Return the indices of the two numbers (1-indexed) as an integer array
@gauravkr0071
gauravkr0071 / Valid Triangle Number.cpp
Created August 12, 2021 17:23
Valid Triangle Number.cpp
/*
611. Valid Triangle Number
Medium
Given an integer array nums, return the number of triplets chosen
from the array that can make triangles if we take them as side
lengths of a triangle.
/*
259: 3Sum Smaller
Given an array of n integers nums and a target, find the number of index triplets i, j, k with 0 <= i < j < k < n that satisfy the condition nums[i] + nums[j] + nums[k] < target.
For example, given nums = [-2, 0, 1, 3], and target = 2.
Return 2. Because there are two triplets which sums are less than 2:
[-2, 0, 1]
@gauravkr0071
gauravkr0071 / 3Sum Closest.cpp
Created August 10, 2021 18:20
3Sum Closest
/*
3Sum Closest
Medium
Given an integer array nums of length n and an integer target,
find three integers in nums such that the sum is closest to target.
Return the sum of the three integers.
You may assume that each input would have exactly one solution.
@gauravkr0071
gauravkr0071 / Max Points on a Line.cpp
Created August 10, 2021 13:08
Max Points on a Line
/*
149. Max Points on a Line
Hard
Given an array of points where points[i] = [xi, yi] represents a point
on the X-Y plane, return the maximum number of points that lie on the
same straight line.
@gauravkr0071
gauravkr0071 / subarray-product-less-than-k.cpp
Created August 10, 2021 08:05
Subarray-product-less-than-k
/*
713. Subarray Product Less Than K
Medium
Given an array of integers nums and an integer k,
return the number of contiguous subarrays where the
product of all the elements in the subarray is strictly less than k.
@gauravkr0071
gauravkr0071 / two sum less than k.cpp
Created August 10, 2021 07:52
two sum less than k
/*
1099. Two Sum Less Than K (https://leetcode.com/problems/two-sum-less-than-k/):
Given an array A of integers and integer K, return the maximum S such that there
exists i < j with A[i] + A[j] = S and S < K. If no i, j exist satisfying
this equation, return -1
*/
@gauravkr0071
gauravkr0071 / Maximum Product of Three Numbers.java
Last active August 10, 2021 07:50
Maximum Product of Three Numbers
/*
628. Maximum Product of Three Numbers
Given an integer array nums, find three numbers whose product is maximum and return the maximum product.
Example 1: