Skip to content

Instantly share code, notes, and snippets.

View rajeakshay's full-sized avatar

Akshay Raje rajeakshay

View GitHub Profile
@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;
@rajeakshay
rajeakshay / ReverseWordsInAString.java
Last active September 18, 2016 12:08
LeetCode 151. Reverse Words in a String - (Problem: https://leetcode.com/problems/reverse-words-in-a-string) - Given an input string, reverse the string word by word. For example, Given s = "the sky is blue", return "blue is sky the". NOTES: A sequence of non-space characters constitutes a word. Remove all leading and trailing spaces. Reduce mul…
/**
* LeetCode 151. Reverse Words in a String (Problem Link: https://leetcode.com/problems/reverse-words-in-a-string)
* Given an input string, reverse the string word by word.
* For example, given s = "the sky is blue", return "blue is sky the".
* NOTES:
* 1. A sequence of non-space characters constitutes a word.
* 2. Remove all leading and trailing spaces.
* 3. Reduce multiple spaces between words into a single space.
*
*/
@rajeakshay
rajeakshay / CountingBits.java
Last active September 18, 2016 12:10
LeetCode 338. Counting Bits - Counting number of set bits in all numbers from 0 to num (Problem: https://leetcode.com/problems/counting-bits) - Given a non negative integer number num. For every number i in the range 0 ≤ i ≤ num, calculate and store the number of 1's in the binary representation of i and return results as an array. Example: For …
/**
* LeetCode 338. Counting Bits
* Counting number of set bits in all numbers from 0 to num (Problem Link: https://leetcode.com/problems/counting-bits)
* Given a non negative integer number num. For every number i in the range 0 ≤ i ≤ num, calculate and store the number of 1's
* in the binary representation of i and return results as an array.
* Example: For num = 5, program should return [0,1,1,2,1,2].
*/
public class CountingBits {
@rajeakshay
rajeakshay / AddTwoNumbers.java
Last active September 18, 2016 12:12
LeetCode 2. Add Two Numbers (Problem: https://leetcode.com/problems/add-two-numbers) - You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. Input: (2 -> 4 -> 3) + (5 -> 6 -> 4) Output: 7 -> 0…
/**
* LeetCode 2. Add Two Numbers (Problem Link: https://leetcode.com/problems/add-two-numbers)
* You are given two linked lists representing two non-negative numbers.
* The digits are stored in reverse order and each of their nodes contain a single digit.
* Add the two numbers and return it as a linked list.
* Input: (2 -> 4 -> 3) + (5 -> 6 -> 4) Output: 7 -> 0 -> 8
*/
/**
* Definition for singly-linked list.
@rajeakshay
rajeakshay / ReverseLinkedListII.java
Last active September 18, 2016 12:09
LeetCode 92. Reverse Linked List II (Problem: https://leetcode.com/problems/reverse-linked-list-ii) - Reverse a linked list from position m to n. Do it in-place and in one-pass. For example: Given 1->2->3->4->5->NULL, m = 2 and n = 4, return 1->4->3->2->5->NULL. Note: Given m, n satisfy the following condition: 1 ≤ m ≤ n ≤ length of list.
/**
* LeetCode 92. Reverse Linked List II (Problem: https://leetcode.com/problems/reverse-linked-list-ii)
* Reverse a linked list from position m to n. Do it in-place and in one-pass.
* For example: Given 1->2->3->4->5->NULL, m = 2 and n = 4, return 1->4->3->2->5->NULL.
* Note: Given m, n satisfy the following condition: 1 ≤ m ≤ n ≤ length of list.
*/
/**
* Definition for singly-linked list.
@rajeakshay
rajeakshay / main.hs
Created March 31, 2016 05:01
Introduction to Haskell - Notes from the 1 hour talk by Greg Hale (@imalsogreg) at Northeastern University.
module Main where
-- This is how you write a comment in Haskell
import Prelude hiding (length) -- Hide length function to define our own later
import Data.List ()
import Data.Char -- required for toUpper
-- Defining your own data types
data MyBool = MyTrue