Skip to content

Instantly share code, notes, and snippets.

View rajeakshay's full-sized avatar

Akshay Raje rajeakshay

  • Bloomberg LP
  • New York, NY
  • 08:27 (UTC -04:00)
View GitHub Profile
@rajeakshay
rajeakshay / rust-book.md
Last active May 29, 2023 18:13
Notes from 'The Rust Programming Language' at https://rust-book.cs.brown.edu/

DISCLAIMER: These notes from 'The Rust Programming Language' book are my own and meant for my personal reference. They are not endorsed by the Rust Foundation. Visit https://www.rust-lang.org/ for the official material for learning Rust.

Installing Rust

  1. Install Rust from https://rustup.rs/.
  2. Check installation with -
    rustc --version
    
    OR
@rajeakshay
rajeakshay / PrintConflictingIntervals.java
Created September 23, 2016 05:27
In a calendar where multiple events can be scheduled over the same time window, print a list of all conflicting time windows along with the event IDs that are conflicting.
/**
* In a calendar where multiple events can be scheduled over the same time window, print a list of all
* conflicting time windows along with the event IDs that are conflicting. All times are in 24 hour format.
* Example:
* Input:
* Event 1 : 2014-01-01 9:45 - 2014-01-01 10:30
* Event 2 : 2014-01-01 10:00 - 2014-01-01 10:30
* Event 3 : 2014-01-01 10:20 - 2014-01-01 10:45
*
* Output:
@rajeakshay
rajeakshay / AllPathsFromASource.java
Created September 23, 2016 05:03
Print all paths from a given source to a destination - (http://www.geeksforgeeks.org/find-paths-given-source-destination/) Given a directed graph, a source vertex ‘s’ and a destination vertex ‘d’, print all paths from given ‘s’ to ‘d’.
/**
* Print all paths from a given source to a destination - (http://www.geeksforgeeks.org/find-paths-given-source-destination/)
* Given a directed graph, a source vertex ‘s’ and a destination vertex ‘d’, print all paths from given ‘s’ to ‘d’.
* */
import java.util.*;
public class AllPathsFromASource {
static class Graph{
int V;
Map<Integer, List<Integer>> adj; // Adjacency list
@rajeakshay
rajeakshay / AllOutcomesOfAnExpression.java
Last active September 19, 2016 07:46
Find all possible outcomes of a given expression - Given an arithmetic expression, find all possible outcomes of this expression. Different outcomes are evaluated by putting brackets at different places. There will be no spaces in the input. Only operators '+','-', and '*' are allowed. Numbers can have multiple digits. Example: Input: 1+3*2 Outp…
/**
* Find all possible outcomes of a given expression (http://www.geeksforgeeks.org/find-all-possible-outcomes-of-a-given-expression/)
* ================================================
* Given an arithmetic expression, find all possible outcomes of this expression. Different outcomes are evaluated by
* putting brackets at different places.
* NOTES:
* 1. There will be no spaces in the input.
* 2. Only operators '+','-', and '*' are allowed.
* 3. Numbers can have multiple digits.
*
@rajeakshay
rajeakshay / InsertInterval.java
Created September 18, 2016 12:06
LeetCode 57. Insert Interval - (Problem Link - https://leetcode.com/problems/insert-interval/) Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary). You may assume that the intervals were initially sorted according to their start times. Example 1: Given intervals [1,3],[6,9], insert and merge [2…
/**
LeetCode 57. Insert Interval
Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).
You may assume that the intervals were initially sorted according to their start times.
Example 1:
Given intervals [1,3],[6,9], insert and merge [2,5] in as [1,5],[6,9].
Example 2:
Given [1,2],[3,5],[6,7],[8,10],[12,16], insert and merge [4,9] in as [1,2],[3,10],[12,16].
@rajeakshay
rajeakshay / SurroundedRegions.java
Last active September 18, 2016 12:14
LeetCode 130. Surrounded Regions - (Problem Link - https://leetcode.com/problems/surrounded-regions/) Given a 2D board containing 'X' and 'O' (the letter O), capture all regions surrounded by 'X'. A region is captured by flipping all 'O's into 'X's in that surrounded region. For example, [X X X X, X O O X, X X O X, X O X X] After running your fu…
/**
LeetCode 130. Surrounded Regions
Given a 2D board containing 'X' and 'O' (the letter O), capture all regions surrounded by 'X'.
A region is captured by flipping all 'O's into 'X's in that surrounded region.
For example,
X X X X
X O O X
X X O X
X O X X
@rajeakshay
rajeakshay / NumberOfIslands.java
Last active September 18, 2016 12:14
LeetCode 200. Number of Islands - (Problem Link: https://leetcode.com/problems/number-of-islands/) Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded b…
/**
*
LeetCode 200. Number of Islands
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands.
An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically.
You may assume all four edges of the grid are all surrounded by water.
Example 1:
11110
11010
11000
@rajeakshay
rajeakshay / DecodeString.java
Last active October 9, 2018 02:13
LeetCode 394. Decode String - (Problem Link - https://leetcode.com/contest/3/problems/decode-string/) Given an encoded string, return it's decoded string. The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is guaranteed to be a positive integer. You may assu…
/**
* LeetCode 394. Decode String - (Problem Link - https://leetcode.com/contest/3/problems/decode-string/)
*
* Given an encoded string, return it's decoded string. The encoding rule is: k[encoded_string], where the encoded_string
* inside the square brackets is being repeated exactly k times. Note that k is guaranteed to be a positive integer.
* You may assume that the input string is always valid; No extra white spaces, square brackets are well-formed, etc.
* Furthermore, you may assume that the original data does not contain any digits and that digits are only for those repeat
* numbers, k. For example, there won't be input like 3a or 2[4].
*
* Examples:
@rajeakshay
rajeakshay / BillPughSingleton.java
Created August 8, 2016 23:06
Two primary approaches of implementing a Singleton class in Java.
/**
*
* Thread-safe singleton with lazy initialization. (Bill Pugh's approach)
*
* NOTES -
* When BillPughSingleton class is loaded, SingletonHelper class is not loaded into memory. Only when someone calls
* getInstance() method, does the SingletonHelper class gets loaded and creates a BillPughSingleton instance.
*
* The advantage comes from the lazy initialization. BillPughSingleton instance, which might be potentially consuming
* very high memory, will only be created when getInstance is called the first time.
@rajeakshay
rajeakshay / DivideTwoIntegers.java
Last active September 18, 2016 12:13
LeetCode 29. Divide Two Integers - (Problem: https://leetcode.com/problems/divide-two-integers) - Divide two integers without using multiplication, division and mod operator. If it is overflow, return MAX_INT.
/**
* LeetCode 29. Divide Two Integers (Problem Link: https://leetcode.com/problems/divide-two-integers)
* Divide two integers without using multiplication, division and mod operator.
* If it is overflow, return MAX_INT. (Integer.MAX_VALUE in Java)
*/
public class DivideTwoIntegers {
public int divide(int dividend, int divisor) {
// Arrr...gh! Divide by zero
if(divisor == 0) return Integer.MAX_VALUE;