Blogs Hub

by AskGif | Sep 25, 2020 | Category :coding

Third Maximum Number - Array - Easy - LeetCode

Third Maximum Number - Array - Easy - LeetCode

Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n). Example 1:<br />Input: [3, 2, 1] Output: 1 Explanation: The third maximum is 1.<br />Example 2:<br />Input

read more...

by AskGif | Sep 25, 2020 | Category :coding

Move Zeroes - Array - Easy - LeetCode

Move Zeroes - Array - Easy - LeetCode

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. Example: Input: [0,1,0,3,12]<br />Output: [1,3,12,0,0]<br />Note: You must do this in-place without making a copy of the array.<br />Minimize

read more...

by AskGif | Sep 25, 2020 | Category :coding

Missing Number - Array - Easy - LeetCode

Missing Number - Array - Easy - LeetCode

Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array. Example 1: Input: [3,0,1]<br />Output: 2<br />Example 2: Input: [9,6,4,2,3,5,7,0,1]<br />Output: 8<br />Note:<br />Your algorithm should run in linear runtime

read more...

by AskGif | Sep 25, 2020 | Category :coding

Contains Duplicate II - Array - Easy - LeetCode

Contains Duplicate II - Array - Easy - LeetCode

Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the absolute difference between i and j is at most k. Example 1: Input: nums = [1,2,3,1], k = 3<br />Output: true<br />Example 2:

read more...

by AskGif | Sep 25, 2020 | Category :coding

Contains Duplicate - Array - Easy - LeetCode

Contains Duplicate - Array - Easy - LeetCode

Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct. Example 1: Input: [1,2,3,1]<br />Output: true<br />Example 2:

read more...

by AskGif | Sep 25, 2020 | Category :coding

Rotate Array - Array - Easy - LeetCode

Rotate Array - Array - Easy - LeetCode

Given an array, rotate the array to the right by k steps, where k is non-negative. Follow up: Try to come up with as many solutions as you can, there are at least 3 different ways to solve this problem.<br />Could you do it in-place with O(1) extra space?<br />&nbsp; Example

read more...

by AskGif | Sep 25, 2020 | Category :coding

Majority Element - Array - Easy - LeetCode

Majority Element - Array - Easy - LeetCode

Given an array of size n, find the majority element. The majority element is the element that appears more than &lfloor; n/2 &rfloor; times. You may assume that the array is non-empty and the majority element always exist in the array. Example 1: Input: [3,2,3]<br />Output: 3

read more...

by AskGif | Sep 25, 2020 | Category :coding

Best Time to Buy and Sell Stock II - Array - Easy - LeetCode

Best Time to Buy and Sell Stock II - Array - Easy - LeetCode

Say you have an array prices for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multiple times). Note: You may not engage i

read more...

by AskGif | Sep 25, 2020 | Category :coding

Pascal's Triangle II - Array - Easy - LeetCode

Pascal's Triangle II - Array - Easy - LeetCode

Given an integer rowIndex, return the rowIndexth row of Pascal's triangle. Notice that the row index starts from 0. <br />In Pascal's triangle, each number is the sum of the two numbers directly above it. Follow up: Could you optimize your algorithm to use only O(k) ex

read more...

by AskGif | Sep 25, 2020 | Category :coding

Pascal's Triangle - Array - Easy - LeetCode

Pascal's Triangle - Array - Easy - LeetCode

Given a non-negative integer numRows, generate the first numRows of Pascal's triangle. <br />In Pascal's triangle, each number is the sum of the two numbers directly above it. Example: Input: 5<br />Output:<br />[<br />&nbsp; &nbsp; &nbsp;[1],<br />&nbsp; &nbsp; [1,1],<br />&

read more...

by AskGif | Sep 25, 2020 | Category :coding

Merge Sorted Array - Array - Easy - LeetCode

Merge Sorted Array - Array - Easy - LeetCode

<pre class="language-csharp"><code>public class Solution { public void Merge(int[] nums1, int m, int[] nums2, int n) { int i=m-1; int j=n-1; for(int x=m+n-1;x&gt;=0;x--){ if(i &gt;= 0 &amp;&amp; j &gt;= 0){ if(nums1[i]&gt;nums2[j]){

read more...

by AskGif | Sep 25, 2020 | Category :coding

Search Insert Position - Array - Easy - LeetCode

Search Insert Position - Array - Easy - LeetCode

Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You may assume no duplicates in the array. Example 1: Input: [1,3,5,6], 5<br />Output: 2<br />Example 2: Input: [1

read more...