This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo -i -u postgres | |
sudo -i -u hritikkumar #for specific user hritikkumar | |
psql #for the psql query command line interface | |
\dt #tables |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.