question_slug
stringlengths
3
77
title
stringlengths
1
183
slug
stringlengths
12
45
summary
stringlengths
1
160
author
stringlengths
2
30
certification
stringclasses
2 values
created_at
stringdate
2013-10-25 17:32:12
2025-04-12 09:38:24
updated_at
stringdate
2013-10-25 17:32:12
2025-04-12 09:38:24
hit_count
int64
0
10.6M
has_video
bool
2 classes
content
stringlengths
4
576k
upvotes
int64
0
11.5k
downvotes
int64
0
358
tags
stringlengths
2
193
comments
int64
0
2.56k
cracking-the-safe
c++ | easy | short
c-easy-short-by-venomhighs7-vsbg
\n\n# Code\n\nclass Solution {\npublic:\n unordered_set<string> hash;\n string ans;\n int k;\n \n void dfs(string u) {\n for (int i = 0; i
venomhighs7
NORMAL
2022-11-01T03:50:37.501495+00:00
2022-11-01T03:50:37.501529+00:00
767
false
\n\n# Code\n```\nclass Solution {\npublic:\n unordered_set<string> hash;\n string ans;\n int k;\n \n void dfs(string u) {\n for (int i = 0; i < k; i++) {\n auto e = u + to_string(i);\n if (!hash.count(e)) {\n hash.insert(e);\n dfs(e.substr(1));\n...
4
1
['C++']
0
cracking-the-safe
C++ | Backtracking | Easy
c-backtracking-easy-by-vaibhavshekhawat-ebrf
```\nclass Solution {\npublic:\n int total;\n unordered_set st;\n bool func(int i,int k,int n,string& s){\n if(i==total) return 1;\n \n
vaibhavshekhawat
NORMAL
2022-07-18T08:27:52.295359+00:00
2022-07-18T08:32:36.253123+00:00
758
false
```\nclass Solution {\npublic:\n int total;\n unordered_set<string> st;\n bool func(int i,int k,int n,string& s){\n if(i==total) return 1;\n \n for(int j=0;j<k;j++){\n s.push_back(j+\'0\');\n \n if(s.size()>=n){\n string a = s.substr(s.size()...
4
0
['Backtracking', 'C']
0
cracking-the-safe
Python DFS Intuitive Explanation
python-dfs-intuitive-explanation-by-_dee-i7z0
I spent hours on this problem getting stuck because I couldn\'t find a clear and intuitive explanation.\n\nThis video provides an awesome intuition: https://www
_deep_
NORMAL
2022-07-08T01:41:54.187593+00:00
2022-07-08T01:53:58.220973+00:00
397
false
I spent hours on this problem getting stuck because I couldn\'t find a clear and intuitive explanation.\n\nThis video provides an awesome intuition: https://www.youtube.com/watch?v=iPLQgXUiU14\n\nThe first half of this video is helpful and also goes through some examples: https://www.youtube.com/watch?v=VZvU1_oPjg0\n\n...
4
0
[]
0
cracking-the-safe
Solution
solution-by-deleted_user-qb58
C++ []\nclass Solution {\npublic:\n using VT = pair<vector<string>,unordered_map<string,int>>;\n VT gNodes(int n, int k) {\n if (n==1) return VT({"
deleted_user
NORMAL
2023-04-25T08:16:59.313553+00:00
2023-04-25T08:29:27.130942+00:00
1,311
false
```C++ []\nclass Solution {\npublic:\n using VT = pair<vector<string>,unordered_map<string,int>>;\n VT gNodes(int n, int k) {\n if (n==1) return VT({""},{{"",0}});\n VT ns;\n auto prev = gNodes(n-1,k).first;\n for (auto s: prev) {\n s += " ";\n for (int i=0; i<k; ...
3
0
['C++', 'Java', 'Python3']
1
cracking-the-safe
backtrack python
backtrack-python-by-djdheeraj5701-4x8h
Have a set of visited permutations\nbase case: if all permutations found then store current string and return True\nrecursion case: \n try all po
djdheeraj5701
NORMAL
2022-08-14T09:42:30.910758+00:00
2022-08-14T09:42:30.910805+00:00
588
false
Have a set of visited permutations\nbase case: if all permutations found then store current string and return True\nrecursion case: \n try all possible i from 0 to k as a new character\n\t\t\t\tcall the function again \n\t\t\t\treturn False if none of them worked\n```\nclass Solution:\n def crackSafe(...
3
0
['Backtracking', 'Recursion', 'Python']
0
cracking-the-safe
Java 2ms DFS
java-2ms-dfs-by-jowangcn-wj96
These are how I reduce the time:\n(1) Use a boolean[] to store which number has been included. and to avoid the transform the number from decimal to other base,
jowangcn
NORMAL
2021-11-29T23:59:10.409104+00:00
2021-11-29T23:59:10.409149+00:00
865
false
These are how I reduce the time:\n(1) Use a boolean[] to store which number has been included. and to avoid the transform the number from decimal to other base, I use the extra space to make it easy. This is quicker than HashSet/HashMap. \n(2) pass the current tested password in integer in the recursion, so that the ne...
3
3
['Depth-First Search', 'Java']
0
cracking-the-safe
[Python 3] De Bruijn Sequence
python-3-de-bruijn-sequence-by-bakerston-h1x1
\ndef crackSafe(self, n: int, k: int) -> str: \n if n == 1:\n return "".join(map(str, range(k)))\n if k == 1:\n return
Bakerston
NORMAL
2021-04-11T01:00:34.343070+00:00
2021-04-11T01:00:34.343121+00:00
402
false
```\ndef crackSafe(self, n: int, k: int) -> str: \n if n == 1:\n return "".join(map(str, range(k)))\n if k == 1:\n return "0" * n\n alpha = list(map(str, range(k)))\n a = [0] * k * n\n seq = []\n def db(t, p):\n if t > n:\n ...
3
0
[]
0
cracking-the-safe
Easy Python solution with explanation
easy-python-solution-with-explanation-by-lyi2
Total number of passwords is k^n. Create a set to record our accessible numbers.\nTo make our key shortest, we need the maximum overlap with every two different
yixizhou
NORMAL
2020-09-30T22:53:30.648128+00:00
2020-09-30T22:53:30.648159+00:00
293
false
Total number of passwords is k^n. Create a set to record our accessible numbers.\nTo make our key shortest, we need the maximum overlap with every two different passwords, which is n-1.\nStart with "0"*n, pick the last n-1 numbers and add other new numbers to the end, if the new number is not in the set, we add it to t...
3
0
[]
3
cracking-the-safe
C++, DFS and backtracking
c-dfs-and-backtracking-by-paulpsp-8kin
You don\'t need to pre generate the graph, you can create it on the fly and each state has to create all the next possible states and record them in a set, the
paulpsp
NORMAL
2020-08-08T00:45:22.708375+00:00
2020-08-08T00:45:22.708412+00:00
403
false
You don\'t need to pre generate the graph, you can create it on the fly and each state has to create all the next possible states and record them in a set, the down side is that you to generate all the other `k` states which might have already been visited previously, but it is easier than maintaining the graph stcutru...
3
0
[]
0
cracking-the-safe
Python short & simple
python-short-simple-by-dylan20-1sp9
\nclass Solution(object):\n def crackSafe(self, n, k):\n toVisit = collections.defaultdict(lambda: map(str, range(k)))\n toVisit["0" * (n - 1)]
dylan20
NORMAL
2018-01-06T16:41:12.224000+00:00
2018-01-06T16:41:12.224000+00:00
754
false
```\nclass Solution(object):\n def crackSafe(self, n, k):\n toVisit = collections.defaultdict(lambda: map(str, range(k)))\n toVisit["0" * (n - 1)] = map(str, range(1, k))\n ans = "0" * n\n while True:\n cur = ans[len(ans) - n + 1:]\n if not toVisit[cur]: return ans\n...
3
0
[]
2
cracking-the-safe
Java Solution
java-solution-by-archivebizzle-t5ug
Intuition\nThe goal is to find the shortest possible password that contains all possible combinations of the given digits\n\n# Approach\nInitialize Variables:\n
archivebizzle
NORMAL
2024-01-11T13:49:51.431291+00:00
2024-01-11T13:49:51.431311+00:00
534
false
# Intuition\nThe goal is to find the shortest possible password that contains all possible combinations of the given digits\n\n# Approach\nInitialize Variables:\n\nCreate a string allZeros containing \'n\' zeros, representing the initial state of the password.\nCreate a StringBuilder sb and initialize it with allZeros....
2
0
['Java']
0
cracking-the-safe
JAVA solution
java-solution-by-21arka2002-udzd
\nclass Solution {\n public String crackSafe(int n, int k) {\n HashSet<String>v=new HashSet<>();\n String ans="";\n for(int i=0;i<n;i++)
21Arka2002
NORMAL
2023-04-28T16:13:25.609682+00:00
2023-04-28T16:13:25.609748+00:00
408
false
```\nclass Solution {\n public String crackSafe(int n, int k) {\n HashSet<String>v=new HashSet<>();\n String ans="";\n for(int i=0;i<n;i++) ans+=\'0\';\n int len = n + (int)Math.pow(k,n) - 1;\n ans=dfs(ans,n,k,v,len);\n return ans;\n }\n public String dfs(String s,int ...
2
0
['Depth-First Search', 'Recursion', 'Java']
0
cracking-the-safe
✅Python 3 - fast (95%+) - explained 😃 - de Bruijn sequence
python-3-fast-95-explained-de-bruijn-seq-e40p
\n\n\n# Intuition\nIt is very intuitive that two adjacent passwords should differ by first and last digits\n- example for n = 3, k = 2:\n\nwe have 8 (2 ** 3) di
noob_in_prog
NORMAL
2023-01-11T12:36:11.138594+00:00
2023-01-11T12:38:13.647861+00:00
317
false
![image.png](https://assets.leetcode.com/users/images/0865974f-c981-497d-9936-701f3f44a38e_1673439994.1812327.png)\n\n\n# Intuition\nIt is very intuitive that two **adjacent passwords** should **differ by first and last digits**\n- example for `n = 3`, `k = 2`:\n```\nwe have 8 (2 ** 3) different passwords\n\nsolution: ...
2
0
['Backtracking', 'Python3']
0
cracking-the-safe
C++ solution, simple to understand
c-solution-simple-to-understand-by-cptsm-vqvm
Constructing a De Bruijn sequence solves the question. For any permutation x, a new permutation y can be obtained by removing the first character of x and appen
CPTSMONSTER
NORMAL
2021-12-27T00:07:22.389553+00:00
2021-12-27T00:07:22.389584+00:00
571
false
Constructing a De Bruijn sequence solves the question. For any permutation x, a new permutation y can be obtained by removing the first character of x and appending a new character to the end of x from the set of letters in [0, k-1]. The first n-1 characters of any permutation can be constructed as nodes in a graph and...
2
1
[]
0
cracking-the-safe
Easy to understand Java DFS
easy-to-understand-java-dfs-by-viveksinu-ae3h
\n/*\nWe need string of n digits with each digit ranging from 0 to k, so max combination = k^n\nstart with "0000" if k=2, then next can be 00001=> this has 2 c
viveksinub
NORMAL
2021-09-03T08:40:59.116634+00:00
2021-09-03T08:40:59.116675+00:00
561
false
```\n/*\nWe need string of n digits with each digit ranging from 0 to k, so max combination = k^n\nstart with "0000" if k=2, then next can be 00001=> this has 2 combinatioons 0000 , 0001\nlast n digits tell the combination\nstart with all 0 add eack of k numbers in end if not visited\n*/\nclass Solution {\n String ...
2
0
[]
0
cracking-the-safe
Java | simple backtracking, space trade off faster than 80%
java-simple-backtracking-space-trade-off-l2wf
Check the suffix substring with size of n\n\nclass Solution {\n \n int maxCombination = 1;\n int K;\n int N;\n String res;\n public boolean cr
zoey_mameshiba
NORMAL
2021-05-07T23:32:09.804158+00:00
2021-05-07T23:34:06.403180+00:00
503
false
Check the suffix substring with size of n\n```\nclass Solution {\n \n int maxCombination = 1;\n int K;\n int N;\n String res;\n public boolean crackSafeHelper(String prefix, Set<String> allCombs) {\n if (prefix.length() >= N \n\t\t\t&& allCombs.contains(prefix.substring(prefix.length() - N))) {...
2
0
[]
0
cracking-the-safe
Swift DFS
swift-dfs-by-johnamcruz-lv13
\nclass Solution {\n var result = ""\n \n func crackSafe(_ n: Int, _ k: Int) -> String {\n if n == 1 && k == 1 {\n return "0"\n
johnamcruz
NORMAL
2020-11-06T09:18:00.809585+00:00
2020-11-06T09:18:00.809612+00:00
191
false
```\nclass Solution {\n var result = ""\n \n func crackSafe(_ n: Int, _ k: Int) -> String {\n if n == 1 && k == 1 {\n return "0"\n }\n \n var visited = Set<String>()\n var start = String(repeating: "0", count: n-1)\n dfs(start, k, &visited)\n result.a...
2
0
[]
0
cracking-the-safe
Java DFS to make sure short circuit!
java-dfs-to-make-sure-short-circuit-by-h-fvph
\nclass Solution {\n int t, n, k;\n public String crackSafe(int n, int k) {\n this.t = (int) Math.pow(k, n);\n this.n = n;\n this.k =
hobiter
NORMAL
2020-03-02T06:48:41.031174+00:00
2020-03-02T06:48:41.031222+00:00
337
false
```\nclass Solution {\n int t, n, k;\n public String crackSafe(int n, int k) {\n this.t = (int) Math.pow(k, n);\n this.n = n;\n this.k = k;\n StringBuilder sb = new StringBuilder();\n String first = String.join("", Collections.nCopies(n, "0"));\n sb.append(first);\n ...
2
0
[]
0
cracking-the-safe
O(k * k^n) just loop
ok-kn-just-loop-by-aqin-nzb3
\nclass Solution {\n public String crackSafe(int n, int k) {\n StringBuilder sb = new StringBuilder();\n Set<String> set = new HashSet<>();\n
aqin
NORMAL
2020-01-28T02:26:35.329607+00:00
2020-01-28T02:26:35.329662+00:00
193
false
```\nclass Solution {\n public String crackSafe(int n, int k) {\n StringBuilder sb = new StringBuilder();\n Set<String> set = new HashSet<>();\n for (int i = 0; i < n; i++){\n sb.append("0");\n }\n set.add(sb.toString());\n boolean stop = false;\n while(!st...
2
0
[]
1
cracking-the-safe
Python DP+DFS solution beats 98%, short explanation
python-dpdfs-solution-beats-98-short-exp-zla0
It is not hard to get that the minimum length for given n and k is k^n+n-1. Then the question becomes:\n1) for any n and k, can we always reach the minimum len
zhipengyu2015
NORMAL
2019-08-21T05:25:25.245129+00:00
2019-08-21T05:25:25.245181+00:00
353
false
It is not hard to get that the minimum length for given `n` and `k` is `k^n+n-1`. Then the question becomes:\n1) for any `n` and `k`, can we always reach the minimum lenth\n2) if 1) is true, how to construct such string with the minimum length\n\n\nFor 1), I don\'t know how to prove it but I can always find the string...
2
0
[]
1
cracking-the-safe
Please Help with my Hamiltonian Path Solution (Passed 37/38 Testcases)
please-help-with-my-hamiltonian-path-sol-ev0a
I made a solution that builds a directed graph showing the current node and the nodes reachable from the current node. (Stored as an adjacency list in dict_).\n
spie2005
NORMAL
2018-12-19T08:18:10.961534+00:00
2018-12-19T08:18:10.961575+00:00
1,737
false
I made a solution that builds a directed graph showing the current node and the nodes reachable from the current node. (Stored as an adjacency list in dict_).\n\nI then run hamiltonian search on this dictionary to find the shortest path that touches every node.\n\nThis solution passed 37/38 testcases. The solution give...
2
0
[]
1
cracking-the-safe
Simple C++ beats 100%
simple-c-beats-100-by-kevincabbage-odka
Say there is a string A the length of which is n - 1. we can put k different digits in front of it to get k different string B whose length is n. And we can als
kevincabbage
NORMAL
2018-10-04T02:33:34.962882+00:00
2018-10-11T07:29:20.913752+00:00
486
false
Say there is a string A the length of which is n - 1. we can put k different digits in front of it to get k different string B whose length is n. And we can also put k different digits at the end of it to get another k different string C.\n\nSo we can always find a digit and add it to the end of previous string, and we...
2
0
[]
0
cracking-the-safe
Java Bitwise DFS beats 90%
java-bitwise-dfs-beats-90-by-crunner-bcqs
Based on the assumptions of k and n, we use 4 bits to represent k and an integer to represent the password.\n\n\n public String crackSafe(int n, int k) {\n
crunner
NORMAL
2018-09-20T01:18:06.235844+00:00
2018-09-20T01:18:06.235891+00:00
314
false
Based on the assumptions of k and n, we use 4 bits to represent k and an integer to represent the password.\n\n```\n public String crackSafe(int n, int k) {\n StringBuilder sb = new StringBuilder();\n for (int i = 0; i < n; i++)\n sb.append(0);\n Set<Integer> visited = new HashSet<Int...
2
0
[]
0
cracking-the-safe
Python simple DFS
python-simple-dfs-by-kleedy-zkge
\nclass Solution(object):\n def crackSafe(self, n, k):\n def dfs(cur, used):\n if len(used) == k**n - 1:\n return [True, cur
kleedy
NORMAL
2018-05-26T05:28:12.949041+00:00
2018-05-26T05:28:12.949041+00:00
558
false
```\nclass Solution(object):\n def crackSafe(self, n, k):\n def dfs(cur, used):\n if len(used) == k**n - 1:\n return [True, cur]\n used.add(cur[-n:])\n for digit in map(str,range(k)):\n new = cur + digit\n if new[-n:] not in used:\n...
2
0
[]
0
cracking-the-safe
6-liner to make new password with (n-1)-prefix (with explanation)
6-liner-to-make-new-password-with-n-1-pr-acsa
This solution is inspired by @\u5728\u7ebf\u75af\u72c2. Here is my brief explanation:\n\nThe problem is actually to ask for de Bruijn sequence (instead of makin
zzg_zzm
NORMAL
2017-12-31T03:51:18.024000+00:00
2017-12-31T03:51:18.024000+00:00
354
false
This solution is inspired by @\u5728\u7ebf\u75af\u72c2. Here is my brief explanation:\n\nThe problem is actually to ask for [de Bruijn sequence](https://en.wikipedia.org/wiki/De_Bruijn_sequence) (instead of making a cyclic sequence, we need to pad the end with first `n-1` chars).\n\nNote that [de Bruijn sequence](https...
2
0
['C++']
0
cracking-the-safe
C++, DFS, 3 ms
c-dfs-3-ms-by-zestypanda-3v6a
\nclass Solution {\npublic:\n string crackSafe(int n, int k) {\n string ans(n, '0');\n if (k == 1) return ans;\n int N = 10000;\n
zestypanda
NORMAL
2017-12-25T05:52:29.820000+00:00
2017-12-25T05:52:29.820000+00:00
1,034
false
```\nclass Solution {\npublic:\n string crackSafe(int n, int k) {\n string ans(n, '0');\n if (k == 1) return ans;\n int N = 10000;\n vector<int> visited(N, 0);\n ans += '1'; // starting with "0..01" due to symmetry\n visited[0] = 1;\n visited[1] = 1;\n int len ...
2
0
[]
0
cracking-the-safe
Java greedy solution
java-greedy-solution-by-hdchen-6rcc
\nclass Solution {\n public String crackSafe(int n, int k) { \n final int total = (int) Math.pow(k, n), mod = (int) Math.pow(10, n - 1)
hdchen
NORMAL
2017-12-25T17:16:10.235000+00:00
2017-12-25T17:16:10.235000+00:00
932
false
```\nclass Solution {\n public String crackSafe(int n, int k) { \n final int total = (int) Math.pow(k, n), mod = (int) Math.pow(10, n - 1);\n final Map<Integer, Integer> map = new HashMap();\n map.put(0, 0);\n final Stack<Integer> stack = new Stack();\n stack.add(0);...
2
1
[]
1
cracking-the-safe
simple py solution - using DFS beats 85%
simple-py-solution-using-bfs-beats-85-by-o6vp
IntuitionApproachComplexity Time complexity: Space complexity: Code
noam971
NORMAL
2025-03-01T09:41:35.278701+00:00
2025-03-01T09:59:07.830625+00:00
53
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
1
0
['Python3']
0
cracking-the-safe
Python - Optimal, simple DFS
python-optimal-simple-dfs-by-babos-c5a1
Approach\n Describe your approach to solving the problem. \nThe key to the DFS is to move to the furthest node from the current one. Starting from passwords of
babos
NORMAL
2024-11-27T23:07:14.415980+00:00
2024-11-27T23:07:14.416005+00:00
60
false
# Approach\n<!-- Describe your approach to solving the problem. -->\nThe key to the DFS is to move to the furthest node from the current one. Starting from passwords of 0s, the next character added should be k-1. Therefore, we loop through the possible digits in reverse order. As a result, there is no need to check for...
1
0
['Python3']
0
cracking-the-safe
Easy C++ Solution | Beats 70% | C++ | DFS
easy-c-solution-beats-70-c-dfs-by-rajhar-y95o
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
rajharsh_24
NORMAL
2024-10-16T06:34:34.814692+00:00
2024-10-16T06:34:34.814723+00:00
42
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
1
0
['Depth-First Search', 'Graph', 'C++']
0
cracking-the-safe
Solution from Marlen09 explained to myself
solution-from-marlen09-explained-to-myse-axre
Intuition\nI\'m only writing this shorter copy of Marlen09\'s solution to reinforce my understanding of the problem.\n\nThe graph we want to create is a graph w
Fustigate
NORMAL
2024-05-17T13:53:02.361282+00:00
2024-05-17T13:53:02.361306+00:00
25
false
# Intuition\nI\'m only writing this shorter copy of Marlen09\'s solution to reinforce my understanding of the problem.\n\nThe graph we want to create is a graph which maps one possible solution to the next possible solution. For example if n = 2 and k = 2, the solution should have 2 digits constructed by numbers in {0,...
1
0
['Depth-First Search', 'Graph', 'Python3']
0
cracking-the-safe
Easy Solution
easy-solution-by-anupamkumar-1-g6p7
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nThe approach used in th
20250411.AnupamKumar-1
NORMAL
2023-09-06T08:12:32.062056+00:00
2023-09-06T08:12:32.062087+00:00
38
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThe approach used in this solution is to find a De Bruijn sequence, which is a sequence containing all possible combinations of characters of length n in a cyclic mann...
1
0
['Java']
0
cracking-the-safe
Easy-to-understand C++ solution, textbook dfs implementation
easy-to-understand-c-solution-textbook-d-vp8x
Approach by Example\nn = 2, k = 2\n\n[00]\n [01]\n [11]\n [10]\n\nWe start with 00, and every time we shift the window right by 1, we hope to find a new pass
taucross9368
NORMAL
2023-04-02T02:47:10.396975+00:00
2023-04-02T03:52:29.484180+00:00
108
false
# Approach by Example\nn = 2, k = 2\n```\n[00]\n [01]\n [11]\n [10]\n```\nWe start with `00`, and every time we shift the window right by 1, we hope to find a new password never tried before, until we have tried all possible passwords.\n\nUse dfs: keep trying above step by step. If we have tried all possible combina...
1
0
['C++']
0
cracking-the-safe
EASY TO UNDERSTAND 70% FASTER C++ SOLUTION
easy-to-understand-70-faster-c-solution-e29do
\nclass Solution {\npublic:\n \n string crackSafe(int n, int k) {\n string ans = string(n,\'0\');\n unordered_set<string> s;\n s.inse
abhay_12345
NORMAL
2022-11-27T08:33:20.521371+00:00
2022-11-27T08:33:20.521411+00:00
2,068
false
```\nclass Solution {\npublic:\n \n string crackSafe(int n, int k) {\n string ans = string(n,\'0\');\n unordered_set<string> s;\n s.insert(ans);\n for(int i = 0; i < (pow(k,n)); i++){\n string pre = ans.substr(ans.length()-n+1);\n for(int j = k-1; j>=0; j--){\n ...
1
0
['Depth-First Search', 'C', 'Iterator', 'Ordered Set', 'C++']
1
cracking-the-safe
The most ugly code but works [Java][backtracking]
the-most-ugly-code-but-works-javabacktra-idvh
The key idea is to check if all possible combination are occured without duplication. And the minLength of String is = Math.pow(k,n) + n - 1. So we can use a h
liuxiaomingskm
NORMAL
2022-07-27T22:27:12.778758+00:00
2022-07-27T22:27:12.778787+00:00
359
false
The key idea is to check if all possible combination are occured without duplication. And the minLength of String is = Math.pow(k,n) + n - 1. So we can use a hashset to store all combination and if it existed, jump to next number.\n```\n\nclass Solution {\n String ans;\n public String crackSafe(int n, int k) {\n...
1
0
['Backtracking', 'Recursion', 'Java']
0
cracking-the-safe
DFS - De Bruijn Sequence - Commented code
dfs-de-bruijn-sequence-commented-code-by-yp2n
\nclass Solution {\npublic:\n string crackSafe(int n, int k) {\n //start with all zeros\n string ans(n,\'0\');\n \n //total no of
gazonda
NORMAL
2022-06-28T09:53:24.554763+00:00
2022-06-28T09:53:24.554813+00:00
349
false
```\nclass Solution {\npublic:\n string crackSafe(int n, int k) {\n //start with all zeros\n string ans(n,\'0\');\n \n //total no of sequences\n int total=pow(k,n);\n unordered_set<int> v;\n \n //storing the integer version of strings in visited array\n ...
1
0
['Depth-First Search', 'C']
0
cracking-the-safe
Python || DFS || Sets || O(k * (k ^ n))
python-dfs-sets-ok-k-n-by-in_sidious-fry0
\nclass Solution:\n def crackSafe(self, n: int, k: int) -> str:\n seen=set()\n def dfs(s,last_n):\n if len(seen)==(k**n): return s\n
iN_siDious
NORMAL
2022-04-07T21:09:27.532011+00:00
2022-04-07T21:13:08.803105+00:00
494
false
```\nclass Solution:\n def crackSafe(self, n: int, k: int) -> str:\n seen=set()\n def dfs(s,last_n):\n if len(seen)==(k**n): return s\n if len(last_n)<n: # If len<n,keep adding zeros as and valid string can be returned\n if len(s+"0")==n: \n ...
1
0
['Depth-First Search', 'Ordered Set', 'Python']
0
cracking-the-safe
Python greedy method 100%
python-greedy-method-100-by-lonelykid-ruc2
Use a base k number to represent node, maximum (n-1) digits.\nStart from 0 and always use largest available edge. \nNext node is (node*k+edge) % nodeNum\n\npyth
lonelykid
NORMAL
2022-02-09T00:44:35.925003+00:00
2022-02-09T00:44:35.925046+00:00
683
false
Use a base k number to represent node, maximum (n-1) digits.\nStart from 0 and always use largest available edge. \nNext node is (node*k+edge) % nodeNum\n\n```python\nclass Solution:\n def crackSafe(self, n: int, k: int) -> str:\n ans = list()\n nodeNum = k**(n-1)\n edges = [k-1]*nodeNum\n\n ...
1
1
['Greedy', 'Python']
0
cracking-the-safe
C#. Euler path. Faster than 100%
c-euler-path-faster-than-100-by-ivananti-9g5d
Alogrithm\nJust a standard Euler path algorithm. Surprise, but it seems to be faster than 100% C# submissions. I thought that De Bruijn approach (Lyndon words)
IvanAntipov
NORMAL
2022-01-30T00:18:36.352212+00:00
2022-01-30T00:39:12.033948+00:00
511
false
# Alogrithm\nJust a standard Euler path algorithm. Surprise, but it seems to be faster than 100% C# submissions. I thought that De Bruijn approach (Lyndon words) should be faster.\n\n\nEach state is represented as the sum for i from 0 to n-2 of i_nth_symbols*k^1. \n\n<img src="https://render.githubusercontent.com/rende...
1
0
['C#']
0
cracking-the-safe
C++ || Graph
c-graph-by-ujjwal2001kant-iptj
```\nclass Solution {\npublic:\n string crackSafe(int n, int k){\n unordered_sets;\n \n string cur="";\n for(int i=0; i<n; i++)\n
ujjwal2001kant
NORMAL
2022-01-07T07:02:01.181176+00:00
2022-05-01T00:22:26.149276+00:00
519
false
```\nclass Solution {\npublic:\n string crackSafe(int n, int k){\n unordered_set<string>s;\n \n string cur="";\n for(int i=0; i<n; i++)\n {\n cur+="0";\n }\n string ans1="";\n s.insert(cur);\n \n ans1+=cur;\n \n int ans=po...
1
0
['Graph']
0
cracking-the-safe
javascript dfs/recursion and iteration 95ms
javascript-dfsrecursion-and-iteration-95-cnjw
dfs/recursion\n\nlet total, k, n, res;\nconst crackSafe = (N, K) => {\n n = N, k = K, total = k ** n;\n res = \'0\'.repeat(n), visit = new Set([res]);\n
henrychen222
NORMAL
2021-11-28T01:43:42.907492+00:00
2021-11-28T01:45:12.685672+00:00
240
false
dfs/recursion\n```\nlet total, k, n, res;\nconst crackSafe = (N, K) => {\n n = N, k = K, total = k ** n;\n res = \'0\'.repeat(n), visit = new Set([res]);\n dfs(visit, res);\n return res;\n};\n\nconst dfs = (visit) => {\n if (visit.size == total) return;\n let pre = res.slice(res.length - n + 1); // l...
1
0
['Depth-First Search', 'Recursion', 'Iterator', 'JavaScript']
1
cracking-the-safe
Swift (DFS + Backtracking) + Visualization + Explanation + Unit tests O(K^n) time O(K^n) space
swift-dfs-backtracking-visualization-exp-9pl6
\n// MARK: Unit Tests\nfunc testExample1(){\n let obj=Solution()\n let n = 1, k = 2\n let output = "10"\n assert(obj.crackSafe(n,k)==output,"failed
amhatami
NORMAL
2021-09-29T05:03:50.845041+00:00
2021-09-29T05:04:28.014726+00:00
360
false
```\n// MARK: Unit Tests\nfunc testExample1(){\n let obj=Solution()\n let n = 1, k = 2\n let output = "10"\n assert(obj.crackSafe(n,k)==output,"failed example 1")\n}\nfunc testExample2(){\n let obj=Solution()\n let n = 2, k = 2\n let output = "01100"\n assert(obj.crackSafe(n,k)==output,"failed e...
1
1
[]
0
cracking-the-safe
JAVA AC DFS
java-ac-dfs-by-gwfz0720-4pd4
\nclass Solution {\n public String crackSafe(int n, int k) {\n Set<String> set = new HashSet<>();\n StringBuilder sb = new StringBuilder();\n
gwfz0720
NORMAL
2021-09-27T18:17:39.032467+00:00
2021-09-27T18:17:39.032512+00:00
296
false
```\nclass Solution {\n public String crackSafe(int n, int k) {\n Set<String> set = new HashSet<>();\n StringBuilder sb = new StringBuilder();\n if(dfs(n, k, set, sb)) //return boolean as mark that sb is the string of mininum length to meet the requirement.\n return sb.toString();\n ...
1
0
[]
0
cracking-the-safe
Really easy to understand python DFS solution
really-easy-to-understand-python-dfs-sol-fl9z
\nclass Solution:\n def crackSafe(self, n: int, k: int) -> str:\n \'\'\'\n n = 2; k = 2\n \n nodes = 00,01,10,11\n 00\n
ikna
NORMAL
2021-09-24T05:42:42.374194+00:00
2021-09-24T05:42:42.374225+00:00
661
false
```\nclass Solution:\n def crackSafe(self, n: int, k: int) -> str:\n \'\'\'\n n = 2; k = 2\n \n nodes = 00,01,10,11\n 00\n 01\n 10 11\n 10 \n \n 00110\n \'\'\'\n out_len = k**n + 1\n \n depth = k**n \n ...
1
2
['Backtracking', 'Depth-First Search', 'Python']
0
cracking-the-safe
c++(0ms 100%)space 100% small solution (only math...)
c0ms-100space-100-small-solution-only-ma-3z66
Runtime: 0 ms, faster than 100.00% of C++ online submissions for Cracking the Safe.\nMemory Usage: 6.2 MB, less than 100.00% of C++ online submissions for Crack
zx007pi
NORMAL
2021-08-25T12:38:41.736080+00:00
2021-08-25T13:15:11.544906+00:00
603
false
Runtime: 0 ms, faster than 100.00% of C++ online submissions for Cracking the Safe.\nMemory Usage: 6.2 MB, less than 100.00% of C++ online submissions for Cracking the Safe.\n```\nclass Solution {\npublic:\n string crackSafe(int n, int k) {\n int table[10000] = {0}, p = --k, div = pow(10, n - 1);\n table[k] = 1;...
1
3
['C', 'C++']
3
cracking-the-safe
C++ | Simple | Eulerian Path
c-simple-eulerian-path-by-dheerajchugh30-um78
\n#include<queue>\n#include<stack>\n#include<string>\n#include<unordered_map>\n\nusing namespace std;\ntypedef unordered_map<string, vector<string>> GRAPH;\n\nu
dheerajchugh303
NORMAL
2021-08-15T20:13:32.561779+00:00
2021-08-15T20:13:32.561811+00:00
526
false
```\n#include<queue>\n#include<stack>\n#include<string>\n#include<unordered_map>\n\nusing namespace std;\ntypedef unordered_map<string, vector<string>> GRAPH;\n\nusing namespace std;\nclass Solution {\nprivate:\n GRAPH generateGraph(int n, int k)\n {\n GRAPH g;\n string str(n, \'0\');\n queue...
1
0
[]
0
cracking-the-safe
C++ | Simple | Hamiltonian Cycle
c-simple-hamiltonian-cycle-by-darkhorse7-my2h
\nclass Solution {\npublic:\n string getHamiltonianSequence(string current,int n, int k, unordered_set<string>& visited) {\n \n if(visited.siz
darkHorse77
NORMAL
2021-07-16T12:07:06.158308+00:00
2021-07-16T12:07:46.704650+00:00
886
false
```\nclass Solution {\npublic:\n string getHamiltonianSequence(string current,int n, int k, unordered_set<string>& visited) {\n \n if(visited.size()==pow(k,n)) //max number of sequences possible\n return "";\n \n for(int i = 0; i<k; ++i){\n \n string next...
1
0
[]
0
cracking-the-safe
Super easy DFS | C++ | 0ms - beats 100%
super-easy-dfs-c-0ms-beats-100-by-_shiva-nb1k
\nclass Solution {\npublic:\n int power(int base, int exponent){\n if(exponent==0)return 1;\n int halfWork = power(base,exponent/2);\n i
_shivam7
NORMAL
2021-05-29T03:56:09.662457+00:00
2021-05-29T03:56:09.662496+00:00
827
false
```\nclass Solution {\npublic:\n int power(int base, int exponent){\n if(exponent==0)return 1;\n int halfWork = power(base,exponent/2);\n if(exponent&1)return halfWork*halfWork*base;\n return halfWork*halfWork;\n }\n \n bool dfs(int u, int n, int k, vector<vector<bool>> &vis, str...
1
0
['Depth-First Search', 'C']
0
cracking-the-safe
C++ short and sweet
c-short-and-sweet-by-galster-7qmc
\nclass Solution {\npublic:\n unordered_set<string> found;\n int totalStates = 0;\n \n string crackSafe(const string &curr, const string &state, int
galster
NORMAL
2021-03-22T03:48:32.356846+00:00
2021-03-22T03:48:32.356875+00:00
333
false
```\nclass Solution {\npublic:\n unordered_set<string> found;\n int totalStates = 0;\n \n string crackSafe(const string &curr, const string &state, int k){\n found.insert(state);\n \n if(found.size() == totalStates){\n return curr;\n }\n \n for(int i = 0;...
1
0
[]
0
cracking-the-safe
python dfs + greedy
python-dfs-greedy-by-shuuchen-1g3v
```\nclass Solution:\n def crackSafe(self, n: int, k: int) -> str:\n \n def dfs(s, seen):\n \n if len(seen) == kn:\n
shuuchen
NORMAL
2021-03-06T04:05:22.669350+00:00
2021-03-06T04:05:22.669384+00:00
362
false
```\nclass Solution:\n def crackSafe(self, n: int, k: int) -> str:\n \n def dfs(s, seen):\n \n if len(seen) == k**n:\n return s\n \n for x in range(k):\n new_s = (s[-n+1:] if n > 1 else \'\') + str(x)\n if new_s in...
1
0
[]
0
cracking-the-safe
Proof: why Eulerian Circuit works, and a strict O(k^n) solution
proof-why-eulerian-circuit-works-and-a-s-dd99
Most solutions assume Eulerian Circuit can generate De Brujin Sequence without proof.\nHere is a nice one:\n\nhttp://www-users.math.umn.edu/~reiner/Classes/DeBr
cal_apple
NORMAL
2020-12-06T17:58:48.734100+00:00
2020-12-06T17:59:32.111955+00:00
371
false
Most solutions assume Eulerian Circuit can generate De Brujin Sequence without proof.\nHere is a nice one:\n\nhttp://www-users.math.umn.edu/~reiner/Classes/DeBruijn.pdf\n\n\nPlus a strict` O(k^n)` solution\n\n```\n\n vector<vector<int>> graph;\n string res;\n int N, k;\n \n // de Brujin sequence can be c...
1
0
[]
1
cracking-the-safe
Easy to understand java solution using DFS
easy-to-understand-java-solution-using-d-vbqe
\nclass Solution {\n public String crackSafe(int n, int k) {\n \n // k possibilities for each of the n digits - total number of combination is
podurisaicharan
NORMAL
2020-08-21T00:31:25.334512+00:00
2020-08-21T00:32:34.432931+00:00
235
false
```\nclass Solution {\n public String crackSafe(int n, int k) {\n \n // k possibilities for each of the n digits - total number of combination is k*k*k...(ntimes) = k^n\n int total = (int)Math.pow(k, n);\n \n // start with the basic one "000000" (n digits)\n StringBuffer sb ...
1
0
[]
0
cracking-the-safe
c# DFS
c-dfs-by-lchunlosaltos-yuin
\npublic class Solution {\n //each password is n digits; \n //treat the password as nodes;\n //visit every nodes once to create the password with all p
lchunlosaltos
NORMAL
2020-05-08T02:40:52.110981+00:00
2020-05-08T02:40:52.111028+00:00
181
false
```\npublic class Solution {\n //each password is n digits; \n //treat the password as nodes;\n //visit every nodes once to create the password with all possible answers in one string.\n //use DFS; the node should be seeds with n-1 "0" and append a number from k each time;\n //Make sure we dont duplicate...
1
0
[]
0
cracking-the-safe
[Python] Short dfs()
python-short-dfs-by-hjscoder-li6v
Explanation\n\nStart from "0"n, using a slide window idea, everytime the window moves toward right for 1 digit, for this digit we have k options to create a new
hjscoder
NORMAL
2020-05-06T00:45:00.817286+00:00
2020-05-06T00:45:00.817338+00:00
239
false
**Explanation**\n\nStart from "0"*n, using a slide window idea, everytime the window moves toward right for 1 digit, for this digit we have k options to create a new string that have never being created before. So we continue creating strings until the amount of unique strings equals to the maxium possible amount => to...
1
0
[]
0
cracking-the-safe
Simple Java Solution[BackTracking]
simple-java-solutionbacktracking-by-xlay-hf9a
\nclass Solution {\n Set<String> visited = new HashSet<>();\n int total = 0;\n StringBuilder ans = new StringBuilder();\n int k;\n private boolea
xlayman
NORMAL
2020-04-26T01:20:29.958376+00:00
2020-04-26T01:20:29.958408+00:00
159
false
```\nclass Solution {\n Set<String> visited = new HashSet<>();\n int total = 0;\n StringBuilder ans = new StringBuilder();\n int k;\n private boolean dfs(String start){\n if(visited.size() == total)\n return true;\n for(int i = 0; i < k; i++){\n String curr = start.sub...
1
0
[]
0
cracking-the-safe
C# Solution DFS
c-solution-dfs-by-leonhard_euler-g259
\npublic class Solution \n{\n public string CrackSafe(int n, int k) \n {\n var sb = new StringBuilder();\n for (int i = 0; i < n; i++) \n
Leonhard_Euler
NORMAL
2020-01-03T07:52:31.793017+00:00
2020-01-03T07:52:31.793068+00:00
179
false
```\npublic class Solution \n{\n public string CrackSafe(int n, int k) \n {\n var sb = new StringBuilder();\n for (int i = 0; i < n; i++) \n sb.Append(\'0\');\n DFS(n, k, sb, new HashSet<string>(new string[] {sb.ToString()}));\n return sb.ToString();\n }\n \n privat...
1
0
[]
0
cracking-the-safe
Simple C++ solution with 2 for loops
simple-c-solution-with-2-for-loops-by-em-ozw6
\nclass Solution \n{\n public:\n string crackSafe(int n, int k) \n {\n string result(n,\'0\');\n unordered_set<string> v;\n for(in
eminem18753
NORMAL
2019-12-05T05:44:01.428545+00:00
2019-12-05T05:53:21.668706+00:00
219
false
```\nclass Solution \n{\n public:\n string crackSafe(int n, int k) \n {\n string result(n,\'0\');\n unordered_set<string> v;\n for(int i=0;i<pow(k,n)-1;i++)\n {\n for(int j=k-1;j>-1;j--)\n {\n string temp=result.substr((int)result.size()-n+1,n-1)...
1
0
[]
0
cracking-the-safe
A Java Solution
a-java-solution-by-david137-id5x
\nclass Solution {\n private Set<String> visited = new HashSet<String>();\n private String ans = "";\n private int goal=1;\n \n public String cra
david137
NORMAL
2019-12-01T21:43:55.359853+00:00
2019-12-01T21:43:55.359892+00:00
256
false
```\nclass Solution {\n private Set<String> visited = new HashSet<String>();\n private String ans = "";\n private int goal=1;\n \n public String crackSafe(int n, int k) {\n visited.clear();\n goal = 1;\n ans="";\n for(int i=0; i < n; i++) {\n goal = goal*k;\n }\n\t...
1
0
[]
0
cracking-the-safe
DFS Hamilton Cycle with explanation - JavaScript
dfs-hamilton-cycle-with-explanation-java-jy0q
\n 1. Get all perms of 0 ... k - 1 of length n (these are nodes of the graph)\n 2. Make a graph where each connection represents an overlap (Hamilton Cycle). A
auwdish
NORMAL
2019-11-02T14:23:24.135234+00:00
2019-11-02T14:28:13.668430+00:00
1,622
false
\n 1. Get all perms of 0 ... k - 1 of length n (these are nodes of the graph)\n 2. Make a graph where each connection represents an overlap (Hamilton Cycle). An overlap means that if we can add one number to the end of a permutation and another permutation is made in the process, then these two permutations overlap. F...
1
0
[]
0
cracking-the-safe
Python, easy to understand DFS
python-easy-to-understand-dfs-by-roozbeh-lvdf
My approach was calculate all the possible sequence for K and N, and then try to find the shortest one. Each node in the DFS is one sequence, and the search is
roozbeh3
NORMAL
2019-10-08T01:48:49.704144+00:00
2019-10-08T01:48:49.704189+00:00
197
false
My approach was calculate all the possible sequence for K and N, and then try to find the shortest one. Each node in the DFS is one sequence, and the search is trying to find the next sequence that has N-1 comming characters with it.\n\nThe runtime was slow, but the memory usage was better than 100% of the submissions....
1
0
[]
1
cracking-the-safe
No Code, Proof of Correctness for Greedy Dequeue Approach
no-code-proof-of-correctness-for-greedy-uudbs
This is basically a re-explanation and expansion of the very excellent proof here.\n\nFirst we define a directed graph structure where the nodes are every possi
supermatthew
NORMAL
2019-08-27T15:37:47.001280+00:00
2019-11-20T16:58:14.458499+00:00
214
false
This is basically a re-explanation and expansion of [the very excellent proof here](https://leetcode.com/problems/cracking-the-safe/discuss/110261/Deque-solution-with-proof).\n\nFirst we define a directed graph structure where the nodes are every possible length-n sequence made from the alphabet {0,1,...,k-1}. Two nod...
1
0
[]
0
cracking-the-safe
N-ary solution [C++]
n-ary-solution-c-by-timd000-kctg
Consider traversing a n-ary tree. There are k^n times of unique traverses starting from the root. The tree has n level. And since each parent node has exact k c
timd000
NORMAL
2019-07-16T05:23:30.976283+00:00
2019-07-16T05:23:30.976328+00:00
186
false
Consider traversing a n-ary tree. There are k^n times of unique traverses starting from the root. The tree has n level. And since each parent node has exact k childs, including the root node, each parent node of a leaf node will be visited k times from other n-1 level paths. That means all k^n paths could be fulfilled ...
1
0
[]
1
find-indices-with-index-and-value-difference-ii
[Java/C++/Python] One Pass, O(1) Space
javacpython-one-pass-o1-space-by-lee215-bjzp
Intuition\nThe brute force solution is two for loop to check all pairs.\n\nIf index difference d = 1,\nit will be more straight forward,\nwe can iterate the arr
lee215
NORMAL
2023-10-15T04:02:34.999875+00:00
2023-10-15T04:02:34.999904+00:00
4,767
false
# **Intuition**\nThe brute force solution is two `for` loop to check all pairs.\n\nIf index difference `d = 1`,\nit will be more straight forward,\nwe can iterate the array `A`,\nand keep minimum and maximum in the prefix of `A`.\n<br>\n\n# **Explanation**\nFor `d > 1`, we can do the same thing.\n`mini` is the index of...
104
3
['C', 'Python', 'Java']
18
find-indices-with-index-and-value-difference-ii
Map vs. Min/Max
map-vs-minmax-by-votrubac-fut1
Min/Max\nI initially came up with the map solution, only then to realize that we can just store min and max value.\nC++\ncpp\nvector<int> findIndices(vector<int
votrubac
NORMAL
2023-10-15T04:00:41.794081+00:00
2023-10-15T04:12:09.214759+00:00
1,739
false
## Min/Max\nI initially came up with the map solution, only then to realize that we can just store min and max value.\n**C++**\n```cpp\nvector<int> findIndices(vector<int>& nums, int indexDifference, int valueDifference) {\n int min_j = 0, max_j = 0;\n for (int i = indexDifference, j = 0; i < nums.size(); ++i, ++...
22
1
['C']
5
find-indices-with-index-and-value-difference-ii
Using priority queue || Very simple and easy to understand solution
using-priority-queue-very-simple-and-eas-5bg2
\n# Approach \n- Find the largest and smallest number which is away from i by indDiff distance. Then check if the smallest and ith or larget and ith having a di
kreakEmp
NORMAL
2023-10-15T04:01:35.004781+00:00
2023-10-15T04:23:30.254747+00:00
2,864
false
\n# Approach \n- Find the largest and smallest number which is away from i by indDiff distance. Then check if the smallest and ith or larget and ith having a diff greater than valueDiff\n- To do so we use min heap and max heap to find max and min after (i+ indDiff)th element\n\n# Code\n```\nclass Solution {\npublic:\n ...
18
2
['C++']
3
find-indices-with-index-and-value-difference-ii
Easy Video Solution (Brute->Optimal) 🔥 || Suffix Max-Min 🔥 || C++,JAVA,PYTHON
easy-video-solution-brute-optimal-suffix-kyfv
Intuition\n Describe your first thoughts on how to solve this problem. \nTry to think about prefix and suffix\n\n# Detailed and easy Video Solution\n\nhttps://y
ayushnemmaniwar12
NORMAL
2023-10-15T05:12:02.280461+00:00
2023-10-19T14:55:47.942978+00:00
1,687
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTry to think about prefix and suffix\n\n# ***Detailed and easy Video Solution***\n\nhttps://youtu.be/neaCFDgBBn8\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThe code finds indices in an array where the absolute...
17
1
['Suffix Array', 'C++', 'Java', 'Python3']
4
find-indices-with-index-and-value-difference-ii
c++||Using Set || Very Easy
cusing-set-very-easy-by-baibhavkr143-79lf
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
baibhavkr143
NORMAL
2023-10-15T04:02:41.840096+00:00
2023-10-15T04:02:41.840118+00:00
1,559
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
13
1
['C++']
3
find-indices-with-index-and-value-difference-ii
[Python3] greedy
python3-greedy-by-ye15-ro0f
\n\nclass Solution:\n def findIndices(self, nums: List[int], indexDifference: int, valueDifference: int) -> List[int]:\n mn = mx = -1 \n for i,
ye15
NORMAL
2023-10-15T04:01:13.256444+00:00
2023-10-15T04:01:13.256465+00:00
556
false
\n```\nclass Solution:\n def findIndices(self, nums: List[int], indexDifference: int, valueDifference: int) -> List[int]:\n mn = mx = -1 \n for i, x in enumerate(nums): \n if i >= indexDifference: \n if mn == -1 or nums[i-indexDifference] < nums[mn]: mn = i-indexDifference\n ...
10
0
['Python3']
0
find-indices-with-index-and-value-difference-ii
Best solution.✅NO Priority queue,NO sliding window. Just plane logic✅✅
best-solutionno-priority-queueno-sliding-c7on
Intuition\nIf we carefully see the problem, it may look like we need to store a lot many things if we are at index i, then we need to know every damn thing abou
adiityyya
NORMAL
2023-10-16T20:37:21.232906+00:00
2023-10-16T20:38:22.676159+00:00
298
false
# Intuition\nIf we carefully see the problem, it may look like we need to store a lot many things if we are at index i, then we need to know every damn thing about the values at indexes i - id, but that\'s not the case.\n\n# Approach\nWe will just keep a record of maximum, and minimum element in the range [0,i-id] if w...
8
1
['Array', 'C++']
1
find-indices-with-index-and-value-difference-ii
✅☑[C++/C/Java/Python/JavaScript] || EXPLAINED🔥
ccjavapythonjavascript-explained-by-mark-z385
PLEASE UPVOTE IF IT HELPED\n\n---\n\n\n# Approaches\n(Also explained in the code)\n1. The function findIndices takes three parameters: nums (a vector of integer
MarkSPhilip31
NORMAL
2023-10-15T07:25:32.310951+00:00
2023-10-15T07:25:32.310974+00:00
465
false
# PLEASE UPVOTE IF IT HELPED\n\n---\n\n\n# Approaches\n**(Also explained in the code)**\n1. The function `findIndices` takes three parameters: `nums` (a vector of integers), `indexDifference` (an integer), and `valueDifference` (an integer). It aims to find a pair of indices in the vector nums such that the absolute di...
6
0
['C', 'Ordered Set', 'C++', 'Java', 'Python3', 'JavaScript']
1
find-indices-with-index-and-value-difference-ii
✅✔️Easy to understand || clean code || C++ Solution ✈️✈️✈️✈️✈️
easy-to-understand-clean-code-c-solution-ly3w
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
ajay_1134
NORMAL
2023-10-15T04:06:03.131650+00:00
2023-10-15T04:06:03.131668+00:00
763
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
6
0
['Array', 'Sliding Window', 'Suffix Array', 'C++']
0
find-indices-with-index-and-value-difference-ii
Simple prefix sum
simple-prefix-sum-by-joe54-s1tx
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
joe54
NORMAL
2023-10-15T04:01:01.460758+00:00
2023-10-15T04:01:01.460779+00:00
571
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n $$O(n)$$\n\n- Space complexity:\n $$O(n)$$\n\n# Code\n```\nclass Solution {\npublic:\n vector<int> findIndices(vector<int>& num...
5
0
['C++']
2
find-indices-with-index-and-value-difference-ii
Easy 4 liner explained O(n) time O(1) space, beats 100%, 100%
easy-4-liner-explained-on-time-o1-space-175df
Intuition\n Describe your first thoughts on how to solve this problem. \nSince we have to find an value which is greater than a given valueDifference which are
flame_blitz
NORMAL
2023-10-15T06:20:05.196305+00:00
2023-10-15T06:21:57.142017+00:00
155
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSince we have to find an value which is greater than a given valueDifference which are atleast indexDifference apart, we can just keep track of max and min values as we come across them and then just evaulate them with the current elemnt ...
4
0
['Array', 'Two Pointers', 'JavaScript']
3
find-indices-with-index-and-value-difference-ii
Java Easy solution - O(N)
java-easy-solution-on-by-abhishek1208-cxyd
\nclass Solution {\n public int[] findIndices(int[] nums, int indexDifference, int valueDifference) {\n int[] ans = new int[]{-1,-1};\n \n
lcabhishek
NORMAL
2023-10-15T04:01:58.953451+00:00
2023-10-15T04:54:57.091641+00:00
454
false
```\nclass Solution {\n public int[] findIndices(int[] nums, int indexDifference, int valueDifference) {\n int[] ans = new int[]{-1,-1};\n \n List<int[]> list = new ArrayList<>();\n int min = 0;\n int max = 0;\n \n \n //store the max and min till the index i\n ...
4
1
['Java']
2
find-indices-with-index-and-value-difference-ii
C++ very easy and optimised solution
c-very-easy-and-optimised-solution-by-aa-pdge
Intuition\n Describe your first thoughts on how to solve this problem. \n\njust use 2 stack and use logic\n\n# Approach\n Describe your approach to solving the
AAA_code
NORMAL
2023-10-17T16:43:06.209498+00:00
2023-10-17T16:43:06.209522+00:00
206
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\njust use 2 stack and use logic\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\nmaking a two- way sliding window type that is sorted\n\n# Complexity\n- Time complexity:\n- o(n);\n<!-- Add your time complexity he...
3
1
['Stack', 'C++']
0
find-indices-with-index-and-value-difference-ii
CPP || Two pointer || 100 % || TC:O(n) SC:O(1)
cpp-two-pointer-100-tcon-sco1-by-kgaurav-ey3h
Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem is about finding two indices in an array such that the absolute difference
kgaurav8026
NORMAL
2023-10-15T19:31:11.434436+00:00
2023-10-15T19:31:11.434454+00:00
220
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem is about finding two indices in an array such that the absolute difference between their values is greater than or equal to a given value and the absolute difference between the indices is greater than or equal to another give...
3
0
['Two Pointers', 'C++']
0
find-indices-with-index-and-value-difference-ii
✅ ✅ Indices with index and value difference | Beginner friendly | Min array & Max array ✅ ✅
indices-with-index-and-value-difference-j8gci
Hi,\n\nApproach: I utilized two arrays to store the minimum and maximum values, then used them to efficiently find indices with the desired value difference.\n\
Surendaar
NORMAL
2023-10-15T17:45:26.909420+00:00
2023-10-15T17:47:39.014407+00:00
106
false
Hi,\n\n**Approach:** I utilized two arrays to store the minimum and maximum values, then used them to efficiently find indices with the desired value difference.\n\n**Intuition:** Instead of a direct brute force approach which would result in TLE, I optimized by iterating through the loop fewer than n^2 times.\n\n**Ste...
3
0
['Array', 'Java']
0
find-indices-with-index-and-value-difference-ii
[C++] Insert the candidates {value, index} into an ordered set
c-insert-the-candidates-value-index-into-fq3n
Intuition\n Describe your first thoughts on how to solve this problem. \nFor each index i, try the minimum and maximum values in the indices j = [i + indexDIffe
pepe-the-frog
NORMAL
2023-10-15T07:22:01.786216+00:00
2023-10-15T07:22:01.786242+00:00
180
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFor each index `i`, try the minimum and maximum values in the indices `j = [i + indexDIfference, n)`\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- for each index `i`, only indices in `[i + indexDifference, n)` ...
3
1
['Ordered Set', 'C++']
0
find-indices-with-index-and-value-difference-ii
Python3 | Binary Search
python3-binary-search-by-tkr_6-xmte
\n\n# Code\n\nclass Solution:\n def findIndices(self, nums: List[int], ind: int, val: int) -> List[int]:\n \n \n \n n=len(nums)\n
TKR_6
NORMAL
2023-10-15T05:44:48.546467+00:00
2023-10-15T05:44:48.546500+00:00
160
false
\n\n# Code\n```\nclass Solution:\n def findIndices(self, nums: List[int], ind: int, val: int) -> List[int]:\n \n \n \n n=len(nums)\n sl=[] #SortedList\n \n for i in range(ind,n):\n insort(sl,[nums[i-ind],i-ind])\n \n a,i1=sl[0]\n ...
3
0
['Binary Search', 'Python', 'Python3']
0
find-indices-with-index-and-value-difference-ii
C++ - Binary Search Solution
c-binary-search-solution-by-omkamble0800-k7jp
Complexity\n- Time complexity: O(nlogn)\n\n- Space complexity: O(n)\n\n# Code\n\nclass Solution {\npublic:\n vector<int> findIndices(vector<int>& nums, int i
omkamble0800
NORMAL
2023-10-15T04:19:17.271597+00:00
2023-10-15T04:19:17.271616+00:00
382
false
# Complexity\n- Time complexity: $$O(nlogn)$$\n\n- Space complexity: $$O(n)$$\n\n# Code\n```\nclass Solution {\npublic:\n vector<int> findIndices(vector<int>& nums, int id, int vd) {\n int n = nums.size();\n set<pair<int, int>> st;\n for(int i = id; i < n; i++){\n st.insert({nums[i - ...
3
1
['Array', 'Binary Search', 'Ordered Set', 'C++']
1
find-indices-with-index-and-value-difference-ii
Simple solution with comments which is easy to understand
simple-solution-with-comments-which-is-e-hj4x
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
Code_Of_Duty
NORMAL
2023-10-15T04:06:05.842691+00:00
2023-10-15T04:06:05.842709+00:00
270
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
3
0
['Array', 'Prefix Sum', 'C++']
0
find-indices-with-index-and-value-difference-ii
🔥GREEDY : O(n) TC || ✅⚡Clean & Best Code
greedy-on-tc-clean-best-code-by-adish_21-19sk
Connect with me on LinkedIN : https://www.linkedin.com/in/aditya-jhunjhunwala-51b586195/\n\n# Complexity\n\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n
aDish_21
NORMAL
2023-10-15T04:03:20.886742+00:00
2023-10-15T04:05:39.405052+00:00
307
false
## Connect with me on LinkedIN : https://www.linkedin.com/in/aditya-jhunjhunwala-51b586195/\n\n# Complexity\n```\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n)\n```\n\n# Code\n# Please Upvote if it helps\uD83E\uDD17\n```\nclass Solution {\npublic:\n vector<int> findIndices(vector<int>& nums, int indexDiffere...
3
0
['Greedy', 'C++']
0
find-indices-with-index-and-value-difference-ii
❇ find-indices-with-index-and-value-difference-ii Images👌 🏆O(N)❤️ Javascript🎯 Memory👀95%🕕 ++Exp
find-indices-with-index-and-value-differ-9zsb
Time Complexity: O(N)\uD83D\uDD55\nSpace Complexity: O(N)\n\n\nvar findIndices = function (nums, indexDifference, valueDifference) {\n if (indexDifference ==
anurag-sindhu
NORMAL
2024-09-26T18:28:08.827261+00:00
2024-09-26T18:30:39.017381+00:00
37
false
**Time Complexity: O(N)\uD83D\uDD55\nSpace Complexity: O(N)**\n\n```\nvar findIndices = function (nums, indexDifference, valueDifference) {\n if (indexDifference == 0) {\n if (valueDifference === 0) {\n return [0, 0];\n }\n }\n\n const bigNumArr = [];\n const bigNumArrIndexMapping =...
2
0
['JavaScript']
0
find-indices-with-index-and-value-difference-ii
Java Simple Two Pointer Solution || With Detail Explanation
java-simple-two-pointer-solution-with-de-kgug
Intuition\n- We take 2 variables, min and max, which stores the indices of min and max element respectively.\n- We start a loop with 2 pointers, one at 0 and th
Shree_Govind_Jee
NORMAL
2024-07-03T15:41:38.580740+00:00
2024-07-03T15:41:38.580773+00:00
73
false
# Intuition\n- We take 2 variables, min and max, which stores the indices of **$$min$$** and **$$max$$** element respectively.\n- We start a loop with **$$2 pointers$$**, one at $$0$$ and the other indexDifference apart from it so we dont have to worry about the condition `Math.abs(i - j) >= indexDifference` as it will...
2
0
['Array', 'Two Pointers', 'Greedy', 'Java']
0
find-indices-with-index-and-value-difference-ii
C++ || Segment Tree || Unique Solution 🔥✅💯
c-segment-tree-unique-solution-by-_kvsch-33mz
\n# Code\n\nclass Solution {\npublic:\n // SEGMENT TREES :- vector<int> seg(1000), vector<int>arr(1000), i = 0, l = 0, h = n-1, x = idx, v = val, (x,y) = (l,
_kvschandra_2234
NORMAL
2024-04-30T14:57:19.610680+00:00
2024-04-30T14:57:38.803954+00:00
20
false
\n# Code\n```\nclass Solution {\npublic:\n // SEGMENT TREES :- vector<int> seg(1000), vector<int>arr(1000), i = 0, l = 0, h = n-1, x = idx, v = val, (x,y) = (l,r).\n void buildSeg1(vector<int>& seg, const vector<int>& arr, int i, int l, int h) {\n if (l == h) {\n seg[i] = arr[l];\n re...
2
0
['Segment Tree', 'C++']
0
find-indices-with-index-and-value-difference-ii
[Java] 2ms, 88%, Sliding Window + CLEAN CODE
java-2ms-88-sliding-window-clean-code-by-f0hf
Approach\n1. Fail fast: if indexDiff >= nums.length, then return {-1,-1} as you cannot have such distant indices\n2. Looking at the indexDiff, you realise that
StefanelStan
NORMAL
2023-11-30T21:33:02.370370+00:00
2023-11-30T21:33:02.370391+00:00
50
false
# Approach\n1. Fail fast: if indexDiff >= nums.length, then return {-1,-1} as you cannot have such distant indices\n2. Looking at the indexDiff, you realise that if you pick i [0..n-indexDiff], then the next available number you can chose if after i + indexDiff.\n - Thus, we observe a gap/window: the other index mus...
2
0
['Two Pointers', 'Java']
0
find-indices-with-index-and-value-difference-ii
Best Java Solution || Beats 100%
best-java-solution-beats-100-by-ravikuma-bghn
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
ravikumar50
NORMAL
2023-10-15T07:34:32.044780+00:00
2023-10-15T07:34:32.044799+00:00
158
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
2
0
['Java']
0
find-indices-with-index-and-value-difference-ii
🔥🔥🔥 Python Simple Solution 🔥🔥🔥
python-simple-solution-by-hululu0405-hk8i
Brute force\n# Intuition\n Describe your first thoughts on how to solve this problem. \nCheck all combination in array.\n# Approach\n Describe your approach to
hululu0405
NORMAL
2023-10-15T06:31:21.656206+00:00
2023-10-16T02:11:56.108761+00:00
167
false
# Brute force\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nCheck all combination in array.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nGo through the array.\n# Complexity\n- Time complexity: O(n^2)\n- Space complexity: O(1)\n# Code\n```\nclass Solution:\n ...
2
0
['Python3']
1
find-indices-with-index-and-value-difference-ii
One pass by record left_min index and left_max index
one-pass-by-record-left_min-index-and-le-a6gn
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
pohanchi
NORMAL
2023-10-15T04:07:46.007385+00:00
2023-10-15T04:07:46.007403+00:00
212
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $...
2
1
['Python3']
0
find-indices-with-index-and-value-difference-ii
Python/Rust/Go, O(n) time, O(1) space with explanation
pythonrustgo-on-time-o1-space-with-expla-d6ym
Intuition\n\nLets look at some array $v_0, v_1, v_2, ... v_n$ and take a look at some position $v_i$. How can we tell that index $i$ will be a part of the resul
salvadordali
NORMAL
2023-10-15T04:07:37.006743+00:00
2023-10-16T23:07:24.634075+00:00
168
false
# Intuition\n\nLets look at some array $v_0, v_1, v_2, ... v_n$ and take a look at some position $v_i$. How can we tell that index $i$ will be a part of the result? For this to happen, there should be some position `j <= i - diff_i` for which `|nums[j] - nums[i]| >= diff_v`.\n\nTo not check for every index, we can just...
2
0
['Go', 'Python3', 'Rust']
0
find-indices-with-index-and-value-difference-ii
[c++] one pass - O(N) time O(1) space
c-one-pass-on-time-o1-space-by-akshay4gu-tfxx
Intuition\n Describe your first thoughts on how to solve this problem. \nyou just need the min or max value till i - indexDifference\n\n# Approach\n Describe yo
Akshay4Gupta
NORMAL
2023-10-15T04:06:08.014607+00:00
2023-10-15T04:06:34.723566+00:00
149
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nyou just need the min or max value till `i - indexDifference`\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- for each i\n - keep finding the min and max for `i - indexDifference`\n - and check if abs diffe...
2
0
['C++']
0
find-indices-with-index-and-value-difference-ii
Beats 100% | Python 3
beats-100-python-3-by-alpha2404-7o81
Please UpvoteCode
Alpha2404
NORMAL
2025-02-15T08:29:58.939559+00:00
2025-02-15T08:29:58.939559+00:00
35
false
# Please Upvote # Code ```python3 [] __import__("atexit").register(lambda: open("display_runtime.txt", "w").write("0")) class Solution: def findIndices(self, nums: List[int], indexDifference: int, valueDifference: int) -> List[int]: mn = mx = -1 for i, x in enumerate(nums): if i>= index...
1
0
['Python3']
0
find-indices-with-index-and-value-difference-ii
python solution
python-solution-by-ayoublaar-phyi
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
AyoubLaar
NORMAL
2024-09-07T18:30:50.517488+00:00
2024-09-07T18:30:50.517523+00:00
15
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n^2)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n...
1
0
['Python3']
0
find-indices-with-index-and-value-difference-ii
Detailed Explanation
detailed-explanation-by-rengubareva-rbkw
Intuition\n1. For i-th element check elements with indexes j: abs(j-i) >= indexDifference\n2. If there is elements which is: abs(nums[i] - nums[j]) >= valueDiff
rengubareva
NORMAL
2024-06-25T13:09:29.602797+00:00
2024-06-25T13:09:29.602821+00:00
134
false
# Intuition\n1. For i-th element check elements with indexes j: ```abs(j-i) >= indexDifference```\n2. If there is elements which is: ```abs(nums[i] - nums[j]) >= valueDifference``` ```return {i, j}```, otherwise continue to check each element till the end of the array.\n3. if there is no such elements, ```return {-1, -...
1
0
['Sliding Window', 'Java']
1
find-indices-with-index-and-value-difference-ii
Python | O(nlogn) | Priority Queue
python-onlogn-priority-queue-by-mandeepg-nz0i
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
mandeepgoyal
NORMAL
2023-10-24T16:03:16.447839+00:00
2023-10-24T16:03:16.447866+00:00
22
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(NlogN)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n\n- Space complexity: O(N)\n<!-- Add your space complexity here, ...
1
0
['Heap (Priority Queue)', 'Python3']
0
find-indices-with-index-and-value-difference-ii
Find Indices With Index and Value Difference II - Easy Java Solution
find-indices-with-index-and-value-differ-4pva
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
whopiyushanand
NORMAL
2023-10-18T07:59:01.775956+00:00
2023-10-18T07:59:01.775978+00:00
54
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $...
1
0
['Array', 'Java']
0
find-indices-with-index-and-value-difference-ii
Same as problem 2903 | java O(n) | Prefix sum
same-as-problem-2903-java-on-prefix-sum-e6x0s
Intuition\nSee\uFF1A https://leetcode.com/problems/find-indices-with-index-and-value-difference-i/solutions/4170252/java-o-n-prefix-sum-100/\n Describe your fir
ly2015cntj
NORMAL
2023-10-17T03:07:57.302927+00:00
2023-10-17T03:08:47.943094+00:00
21
false
# Intuition\nSee\uFF1A https://leetcode.com/problems/find-indices-with-index-and-value-difference-i/solutions/4170252/java-o-n-prefix-sum-100/\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n...
1
0
['Java']
0
find-indices-with-index-and-value-difference-ii
Simple and easy || min-max || O(n)
simple-and-easy-min-max-on-by-spats7-lbkz
```\nclass Solution {\n public int[] findIndices(int[] nums, int indexDifference, int valueDifference) {\n int n = nums.length;\n int[][] minMa
spats7
NORMAL
2023-10-16T21:26:09.227671+00:00
2023-10-16T21:26:09.227695+00:00
299
false
```\nclass Solution {\n public int[] findIndices(int[] nums, int indexDifference, int valueDifference) {\n int n = nums.length;\n int[][] minMax = new int[n][4];\n \n minMax[n-1][0] = nums[n-1];\n minMax[n-1][1] = n-1;\n \n minMax[n-1][2] = nums[n-1];\n minMax[...
1
0
['Array', 'Java']
0
find-indices-with-index-and-value-difference-ii
C#: O(n)
c-on-by-igor0-5kmy
Intuition\nGo from the end to the begin of the array nums. Keep the min and max.\n\n# Approach\nGo from the end to the indexDifference position of the array num
igor0
NORMAL
2023-10-16T16:16:40.169338+00:00
2023-10-16T16:16:40.169365+00:00
19
false
# Intuition\nGo from the end to the begin of the array `nums`. Keep the min and max.\n\n# Approach\nGo from the end to the `indexDifference` position of the array `nums`\n```\nfor (int i = nums.Length - 1; i >= indexDifference; i--)\n{\n```\nBy each iteration change the min and max:\n```\n min = Math.Min(min, nums[i...
1
0
['Prefix Sum', 'C#']
0
find-indices-with-index-and-value-difference-ii
C++ || Two Pointer || without set or heap
c-two-pointer-without-set-or-heap-by-moh-8j1m
Intuition\nMaintaining minimum and maximum element in range [0 i-indexDifference]\n\n# Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\nO(1)\n# Code
mohaldarprakash
NORMAL
2023-10-15T10:13:57.643193+00:00
2023-10-15T10:13:57.643225+00:00
277
false
# Intuition\nMaintaining minimum and maximum element in range [0 i-indexDifference]\n\n# Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\nO(1)\n# Code\n```\nfunc abs(n int) int {\n if n < 0 {\n return -n\n }\n return n\n}\n\nfunc findIndices(nums []int, indexDifference int, valueDifference i...
1
0
['Two Pointers', 'Go']
0