Tag: leetcode

  • Find First and Last Position of Element in Sorted Array

    Given an array of integers nums sorted in non-decreasing order, find the starting and ending position of a given target value. If target is not found in the array, return [-1, -1]. You must write an algorithm with O(log n) runtime complexity. Example 1: Input: nums = [5,7,7,8,8,10], target = 8 Output: [3,4] Example 2: Input: nums = [5,7,7,8,8,10], target = 6 Output: [-1,-1] Example…

  • Continuous Subarray Sum

    Given an integer array nums and an integer k, return true if nums has a good subarray or false otherwise. A good subarray is a subarray where: Note that: Example 1: Input: nums = [23,2,4,6,7], k = 6 Output: true Explanation: [2, 4] is a continuous subarray of size 2 whose elements sum up to 6. let’s break down this code visually. The goal is to…

  • Binary Tree Vertical Order Traversal

    Given the root of a binary tree, return the vertical order traversal of its nodes’ values. (i.e., from top to bottom, column by column). If two nodes are in the same row and column, the order should be from left to right. Input: root = [3,9,20,null,null,15,7]Output: [[9],[3,15],[20],[7]]Input: root = [3,9,8,4,0,1,7]Output: [[4],[9],[3,0,1],[8],[7]] Vertical Order Traversal Algorithm Explained The vertical order traversal…