Sliding Window and Spiral Matrix Algorithms

Problem Description Given an array of n positive integers and a positive integer target, find the length of the shortest continuous subarray whose sum is at least target. Return the length of this subarray. If no such subarray exists, return 0. Example 1: Input: target = 7, nums = [2,3,1,2,4,3] Output: 2 Explanation: The subarray [4,3] has the ...

Posted on Thu, 04 Jun 2026 16:09:14 +0000 by 8mycsh

Efficient Array Algorithms: Two Pointers, Sliding Windows, and Matrix Simulation

Squares of a Sorted Array (LeetCode 977) The challenge in squaring a sorted array that contaisn negative numbers is that the largest squares can appear at both ends of the array. While a naive solution involves squaring every element and then sorting the array in $O(n \log n)$ time, a more efficient $O(n)$ approach utilizes the two-pointer tech ...

Posted on Wed, 20 May 2026 06:33:31 +0000 by jskywalker

Arrays and Matrix Operations in C

Exercise 1: Array Memory Layout This program demonstrates memory allocation patterns for one-dimensional and two-dimensional arrays: #include <stdio.h> #define ROWS 4 #define COLS 2 void show_1d_layout() { int vector[ROWS] = { 10, 20, 30, 40 }; printf("Vector size: %d bytes\n", sizeof(vector)); for (int i = 0; ...

Posted on Fri, 15 May 2026 21:24:11 +0000 by symantec

Efficient In-Place Matrix Zeroing Using First Row and Column Markers

Given an m x n matrix, if an element is zero, set its entire row and column to zero. The challenge is to perform this modification in place without using extra matrix storage. The key idea: use the first row and first column as flag storage to record which rows and columns need zeroing, then apply the changes in a final pass. Algorithm Outline ...

Posted on Thu, 14 May 2026 01:15:41 +0000 by Muntjewerf

Minimum Path Sum in a Grid Using Dynamic Programming

Given a grid of non-negative integers, find the path from the top-left corner to the bottom-right corner that miniimzes the sum of the values along the path. Movement is restricted to only down or right directions. Example 1: Input: [[1,3,1],[1,5,1],[4,2,1]] Output: 7 Explanation: The path 1→3→1→1→1 yields the minimum sum. Example 2: Input: [[1 ...

Posted on Sun, 10 May 2026 08:09:15 +0000 by tcl4p