leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

commit dc9c4c4049c56d0b70902ccb9bdde3c32f217a79
parent 20cef8f82d148684351d796af7fd5b21b1c41a7e
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Tue,  2 Jul 2024 15:29:44 +0200

1 Random Problem

Diffstat:
AProblems/2661.cpp | 24++++++++++++++++++++++++
MREADME.md | 1+
2 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/Problems/2661.cpp b/Problems/2661.cpp @@ -0,0 +1,24 @@ +class Solution { + public: + int firstCompleteIndex(const vector<int> &arr, const vector<vector<int>> &mat) const { + static tuple<int, int> mapping[100001]; + static int rc[100001][2]; + const int n = size(mat), m = size(mat[0]); + + memset(rc, 0x00, 8 * size(arr)); + + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + mapping[mat[i][j]] = {i, j}; + } + } + + for (int i = 0; i < size(arr); i++) { + const auto [c, r] = mapping[arr[i]]; + if (++rc[r][0] == n) return i; + if (++rc[c][1] == m) return i; + } + + return -1; + } +}; diff --git a/README.md b/README.md @@ -1214,6 +1214,7 @@ for solving problems. | 2642 | Hard | [Design Graph With Shortest Path Calculator](Problems/2642.cpp) | | 2657 | Medium | [Find the Prefix Common Array of Two Arrays](Problems/2657.cpp) | | 2658 | Medium | [Maximum Number of Fish in a Grid](Problems/2658.cpp) | +| 2661 | Medium | [First Completely Painted Row or Column](Problems/2661.cpp) | | 2665 | Easy | [Counter II](Problems/2665.js) | | 2666 | Easy | [Allow One Function Call](Problems/2666.js) | | 2667 | Easy | [Create Hello World Function](Problems/2667.js) |