Skip to content
Closed

ww #1503

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions 209-minimum-size-subarray-sum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// problem link https://leetcode.com/problems/minimum-size-subarray-sum/submissions/612844825/
// time complexity is O(n).

var minSubArrayLen = function(target, nums) {

let total = 0;
let min_length = Number.MAX_SAFE_INTEGER;
let left_pointer = 0;
for(let i = 0; i < nums.length; i++) {

total += nums[i];
while(total >= target) {
min_length = Math.min(min_length, i + 1 - left_pointer);
total -= nums[left_pointer];
left_pointer = left_pointer+1;
}
}

if(min_length == Number.MAX_SAFE_INTEGER) {
return 0;
} else {
return min_length;
}
};

30 changes: 30 additions & 0 deletions javascript/36-valid-sudoku.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

// the time complexity is constant as we only going to have a 9*9 matrix.
// problem link: https://leetcode.com/problems/valid-sudoku

var isValidSudoku = function(board) {


let rows = [];
let columns = [];
let boxes = [];
for(let i = 0; i < board.length; i++) {
rows.push(new Set());
columns.push(new Set());
boxes.push(new Set());
}

for(let i = 0; i < board.length; i++) {
for(let j = 0; j < board[0].length; j++) {
const boxIndex = 3 * Math.floor(i/3) + Math.floor(j/3);
let curruntCell = board[i][j];
if(rows[i].has(curruntCell) || columns[j].has(curruntCell) || boxes[boxIndex].has(curruntCell)) return false;
if(curruntCell == '.') continue;
rows[i].add(curruntCell);
columns[j].add(curruntCell);
boxes[boxIndex].add(curruntCell);
}
}

return true;
};
23 changes: 23 additions & 0 deletions javascript/560-subarray-sum-equals-k.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Problem link https://leetcode.com/problems/subarray-sum-equals-k
// Time Complexity: O(n)


var subarraySum = function(nums, k) {



const prefixMap = {};
let totalSubArray = 0;
let ongoingSum = 0;

prefixMap[0] = 1;
for(let i = 0; i < nums.length; i++) {
ongoingSum += nums[i];
if(prefixMap[ongoingSum - k]){
totalSubArray += prefixMap[ongoingSum - k];
}
prefixMap[ongoingSum] = (prefixMap[ongoingSum] ? prefixMap[ongoingSum] + 1: 1);
}

return totalSubArray;
};
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy