leetcode

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

commit 31e031c600c89fe462f2455d086bcdcbd8642b75
parent 4f66e7b9daf59fc73f88368aa6769770753f1445
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Sat, 10 Feb 2024 22:43:17 +0000

1 Random Problem

Diffstat:
AProblems/3015.cpp | 17+++++++++++++++++
MREADME.md | 1+
2 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/Problems/3015.cpp b/Problems/3015.cpp @@ -0,0 +1,17 @@ +class Solution { + public: + vector<int> countOfPairs(int n, int x, int y) const { + vector<int> res(n); + + x--, y--; + if (x > y) swap(x, y); + for (int i = 0; i < n - 1; i++) { + for (int j = i + 1; j < n; j++) { + const int dist = min(abs(i - j), abs(i - x) + abs(j - y) + 1); + res[dist - 1] += 2; + } + } + + return res; + } +}; diff --git a/README.md b/README.md @@ -1127,3 +1127,4 @@ for solving problems. | 2947 | Medium | [Count Beautiful Substrings I](Problems/2947.cpp) | | 2966 | Medium | [Divide Array Into Arrays With Max Difference](Problems/2966.cpp) | | 2997 | Medium | [Minimum Number of Operations to Make Array XOR Equal to K](Problems/2997.cpp) | +| 3015 | Medium | [Count the Number of Houses at a Certain Distance I](Problems/3015.cpp) |