September 15, 2019 by Sandeep Bhardwaj | Tags: Leetcode Datastructure & Algorithms

Sort Array By Parity /** * 905. Sort Array By Parity * Given an array A of non-negative integers, return an array consisting of all the even elements of A, followed by all the odd elements of A. * <p> * You may return any answer array that satisfies this condition. * <p> * Exam...

Read moreSeptember 15, 2019 by Sandeep Bhardwaj | Tags: Leetcode Datastructure & Algorithms

Maximum Subarray - Kadane's Algorithm /** * 53. Maximum Subarray - Kadane's Algorithm * <p> * Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum * and return its sum. * <p> * Example: * <p> * Input: [-2,1...

Read moreJuly 26, 2019 by Sandeep Bhardwaj | Tags: Leetcode Datastructure & Algorithms

Valid Parentheses /** * 20. Valid Parentheses * <p> * Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. * <p> * An input string is valid if: * <p> * Open brackets must be closed by the same type of brac...

Read moreJuly 25, 2019 by Sandeep Bhardwaj | Tags: Leetcode Datastructure & Algorithms

Find All Numbers Disappeared in an Array /** * 448. Find All Numbers Disappeared in an Array * <p> * Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once. * <p> * Find all the elements of [1, n] inclusive that do no...

Read moreJuly 24, 2019 by Sandeep Bhardwaj | Tags: Leetcode Datastructure & Algorithms

Move Zeroes /** * 283. Move Zeroes * <p> * Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the * non-zero elements. * <p> * Example: * <p> * Input: [0,1,0,3,12] * Output: [1,3,12,0,0] * Note: * <p> ...

Read more