Skip to content

Instantly share code, notes, and snippets.

View hrit-ikkumar's full-sized avatar

Hritik Kumar Sharma hrit-ikkumar

View GitHub Profile
/**
* Definition for singly-linked list.
* class ListNode {
* public int val;
* public ListNode next;
* ListNode(int x) { val = x; next = null; }
* }
*/
public class Solution {
public ListNode mergeKLists(ArrayList<ListNode> a) {
public class Solution {
public ArrayList<Integer> findOccurences(ArrayList<Integer> A) {
// create map of whole array
HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
for(int x: A) map.merge(x, 1, Integer::sum);
ArrayList<Integer> result = new ArrayList<>();
// sort the array for increasing order
Collections.sort(A);
// iterate through whole array to get the count and set its count to 0 we have accessed the element
public class Solution {
public int solve(ArrayList<Integer> A, int B) {
// PriorityQueue for max heap
// By default priority queue is min heap
// we want to maximize profit that is reason we are using max heap
PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());
// add all the elements into the heap
for(int x: A) pq.add(x);
int ans = 0;
public class Solution {
// DO NOT MODIFY THE LIST. IT IS READ ONLY
public int solve(final List<Integer> A) {
// calculate sum of A
int sum = 0;
int n = A.size();
for(int x: A) sum+= x;
sum/=2;
public class Solution {
// DO NOT MODIFY THE LIST. IT IS READ ONLY
public int solve(final List<Integer> friendCapacity, final List<Integer> dishCapacity, final List<Integer> dishCost) {
// get maximum cost of all friend
int maxFriendCost = Collections.max(friendCapacity);
// generate dp table for that maximum friend cost
List<List<Integer>> dpTable = getMinCost(dishCapacity, dishCost, maxFriendCost);
// use the dp_table for each friends' cost
int result = 0;
sudo -i -u postgres
sudo -i -u hritikkumar #for specific user hritikkumar
psql #for the psql query command line interface
\dt #tables
/**
* Implementation of finding an Eulerian Path on a graph. This implementation verifies that the
* input graph is fully connected and supports self loops and repeated edges between nodes.
*
* <p>Test against: https://open.kattis.com/problems/eulerianpath
* http://codeforces.com/contest/508/problem/D
*
* <p>Run: ./gradlew run -Palgorithm=graphtheory.EulerianPathDirectedEdgesAdjacencyList
*
* <p>Time Complexity: O(E)
mongod --dbpath=data/ --bind_ip 127.0.0.1
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.