From c39a2588d5191978c203deb4328e9a5f7c22526e Mon Sep 17 00:00:00 2001 From: chayan das <110921638+Chayandas07@users.noreply.github.com> Date: Thu, 6 Mar 2025 23:36:36 +0530 Subject: [PATCH] Create 2965. Find Missing and Repeated Values --- 2965. Find Missing and Repeated Values | 30 ++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 2965. Find Missing and Repeated Values diff --git a/2965. Find Missing and Repeated Values b/2965. Find Missing and Repeated Values new file mode 100644 index 0000000..aeea7d1 --- /dev/null +++ b/2965. Find Missing and Repeated Values @@ -0,0 +1,30 @@ +#include +using namespace std; + +class Solution { +public: + vector findMissingAndRepeatedValues(vector>& grid) { + int n = grid.size(); + vector res(2); + vector num(n * n + 1, 0); + + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (num[grid[i][j]] == 1) { + res[0] = grid[i][j]; + } else { + num[grid[i][j]] = 1; + } + } + } + + for (int i = 1; i <= n * n; i++) { + if (num[i] == 0) { + res[1] = i; + break; + } + } + + return res; + } +};