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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
snakes-and-ladders | C++ || BFS || Easy To Understand || Beginner Friendly | c-bfs-easy-to-understand-beginner-friend-d4yz | \nclass Solution {\npublic:\n int snakesAndLadders(vector<vector<int>>& board) {\n int n = board.size();\n \n // store the position of e | Tyfoon | NORMAL | 2023-01-24T03:53:47.470321+00:00 | 2023-01-24T03:53:47.470350+00:00 | 451 | false | ```\nclass Solution {\npublic:\n int snakesAndLadders(vector<vector<int>>& board) {\n int n = board.size();\n \n // store the position of each cell in a map\n map<int,pair<int,int>> mp;\n int goal = 1;\n int t = 1;\n for(int i=n-1; i>= 0; i--){\n if(t == 0)... | 3 | 0 | ['Breadth-First Search', 'C++'] | 0 |
snakes-and-ladders | C++ | BFS | video solution | c-bfs-video-solution-by-alien35-fype | Intuition & Approach\nhttps://youtu.be/2borKYoRgJw\n\n# Code\n\nclass Solution {\npublic:\n int snakesAndLadders(vector<vector<int>>& board) {\n int n | Alien35 | NORMAL | 2023-01-24T02:25:29.356970+00:00 | 2023-01-24T02:25:29.357002+00:00 | 1,539 | false | # Intuition & Approach\nhttps://youtu.be/2borKYoRgJw\n\n# Code\n```\nclass Solution {\npublic:\n int snakesAndLadders(vector<vector<int>>& board) {\n int n = board.size();\n \n vector<pair<int, int>> idxs(n * n + 1);\n int idx = 1;\n \n vector<int> cols(n);\n iota(col... | 3 | 0 | ['C++'] | 0 |
snakes-and-ladders | BFS SOLUTION JAVA :) ! | bfs-solution-java-by-mutablestringz-w4kv | Since constraints are low, just simulate this process with a bfs and you will come to your answer in the minimum number of moves possible! Quite a lot of code, | MutableStringz | NORMAL | 2023-01-24T01:26:19.404432+00:00 | 2023-01-24T01:26:19.404461+00:00 | 746 | false | Since constraints are low, just simulate this process with a bfs and you will come to your answer in the minimum number of moves possible! Quite a lot of code, but not a hard concept. See below for implementation and upvote if you liked!\n\n# Code\n```\nclass Solution {\n public int snakesAndLadders(int[][] board) {... | 3 | 0 | ['Java'] | 1 |
snakes-and-ladders | C++ Solution || Easy || BFS || Unordered Map | c-solution-easy-bfs-unordered-map-by-inr-xp1b | \n# Code\n\nclass Solution {\npublic:\n int snakesAndLadders(vector<vector<int>>& board) {\n int n = board.size();\n unordered_map<int,int> mp; | inrittik | NORMAL | 2022-12-24T06:17:04.707861+00:00 | 2022-12-24T06:17:04.707909+00:00 | 115 | false | \n# Code\n```\nclass Solution {\npublic:\n int snakesAndLadders(vector<vector<int>>& board) {\n int n = board.size();\n unordered_map<int,int> mp; // map box number to the value it holds\n int steps = 1, dir=0;\n for(int i=n-1; i>=0; --i){\n for(int j=0; j<n && dir==0; ++j){\n ... | 3 | 0 | ['C++'] | 1 |
snakes-and-ladders | Easy to understand JavaScript solution (BFS) | easy-to-understand-javascript-solution-b-up2e | \nvar snakesAndLadders = function(board) {\n const { length: n } = board;\n const DESTINATION = n * n;\n const visited = new Set();\n const queue = | tzuyi0817 | NORMAL | 2022-12-03T08:56:16.089907+00:00 | 2023-01-28T07:46:24.186402+00:00 | 419 | false | ```\nvar snakesAndLadders = function(board) {\n const { length: n } = board;\n const DESTINATION = n * n;\n const visited = new Set();\n const queue = [1];\n let result = 0;\n\n while (queue.length) {\n const size = queue.length;\n\n for (let index = 0; index < size; index++) {\n ... | 3 | 0 | ['JavaScript'] | 1 |
snakes-and-ladders | Why can't be this done using DFS with dp optimization | why-cant-be-this-done-using-dfs-with-dp-nwzph | I was trying to go for the DFS approach and I can\'t figure out why is it not working\n\nclass Solution {\npublic:\n int func(vector<int>&linear,int index,ve | Suyash07 | NORMAL | 2022-11-08T20:12:18.122537+00:00 | 2022-11-08T20:12:18.122582+00:00 | 922 | false | I was trying to go for the DFS approach and I can\'t figure out why is it not working\n```\nclass Solution {\npublic:\n int func(vector<int>&linear,int index,vector<int>&dp)\n {\n if(index>=linear.size()-1)return 0;\n if(index<0 )return 100000;\n \n \n if(linear[index]==-2)return ... | 3 | 0 | ['Dynamic Programming', 'Depth-First Search', 'Graph'] | 3 |
snakes-and-ladders | Standard BFS approach || C++ Solution | standard-bfs-approach-c-solution-by-agra-jx4y | This a standard bfs problem. The only tricky part about this question is to get cell coordinates (row,col) from the cell value. To get cell coordinates, i\'ve m | agraj_23 | NORMAL | 2022-06-14T12:53:01.269506+00:00 | 2022-06-15T08:54:43.765184+00:00 | 259 | false | This a standard bfs problem. The only tricky part about this question is to get cell coordinates (row,col) from the cell value. To get cell coordinates, i\'ve made a separate function which will clearly demonstrate how to get the coordinates. You can look at the rest of the code, you will not find any difference compar... | 3 | 0 | ['Breadth-First Search', 'C'] | 0 |
snakes-and-ladders | neetcode video translation | neetcode-video-translation-by-jeancalgar-3hin | \nclass Solution { \npublic:\n int snakesAndLadders(vector<vector<int>>& board) {\n int length = board.size();\n reverse(board.begin(), boar | jeancalgary | NORMAL | 2022-01-09T00:06:23.756308+00:00 | 2022-01-09T00:06:23.756347+00:00 | 117 | false | ```\nclass Solution { \npublic:\n int snakesAndLadders(vector<vector<int>>& board) {\n int length = board.size();\n reverse(board.begin(), board.end());\n function<pair<int,int>(int)> intToPos = [&](int square) {\n square -= 1;\n int r = square / length;\n int... | 3 | 0 | [] | 0 |
snakes-and-ladders | BFS || Queue and Visited || Java || Easy | bfs-queue-and-visited-java-easy-by-akhil-qh00 | If you like this please upvote and like\nSuggest me some more ways to do this question\n\nclass Solution {\npublic int snakesAndLadders(int[][] board) {\n | AkhilSharma24 | NORMAL | 2021-10-19T04:21:06.645533+00:00 | 2021-10-19T04:21:06.645567+00:00 | 339 | false | **If you like this please upvote and like**\n**Suggest me some more ways to do this question**\n```\nclass Solution {\npublic int snakesAndLadders(int[][] board) {\n int n = board.length;\n int steps = 0;\n Queue<Integer> q = new LinkedList<Integer>();\n boolean visited[][] = new boolean[n][n];\n ... | 3 | 0 | [] | 1 |
snakes-and-ladders | [Python] BFS with detailed comments | python-bfs-with-detailed-comments-by-hid-qfim | \nclass Solution:\n def snakesAndLadders(self, board: List[List[int]]) -> int:\n queue = collections.deque()\n n = len(board)\n queue.ap | hideinsea | NORMAL | 2021-10-10T05:00:27.859637+00:00 | 2021-10-10T05:00:50.934402+00:00 | 531 | false | ```\nclass Solution:\n def snakesAndLadders(self, board: List[List[int]]) -> int:\n queue = collections.deque()\n n = len(board)\n queue.append((1, 0)) # (label, path_len)\n visited = set()\n \n def square_to_idx(val):\n row_idx = n - 1 - (val - 1) // n\n ... | 3 | 0 | ['Breadth-First Search', 'Python'] | 1 |
snakes-and-ladders | Easy C++ BFS solution || commented | easy-c-bfs-solution-commented-by-saiteja-trlv | \nclass Solution {\npublic:\n int snakesAndLadders(vector<vector<int>>& board) {\n \n //get the top right value\n \n int n=board. | saiteja_balla0413 | NORMAL | 2021-07-27T13:47:51.594375+00:00 | 2021-07-27T13:47:51.594419+00:00 | 552 | false | ```\nclass Solution {\npublic:\n int snakesAndLadders(vector<vector<int>>& board) {\n \n //get the top right value\n \n int n=board.size();\n int toReach=n*n;\n \n \n \n //to store ht values which are visited\n unordered_set<int> s;\n queue<... | 3 | 0 | ['C'] | 1 |
snakes-and-ladders | [c++] using BFS | c-using-bfs-by-anandbarnwal-u9jg | \nint snakesAndLadders(vector<vector<int>>& board) {\n int R = board.size();\n int C = board[0].size(); \n int dest = R * C;\n | anandbarnwal | NORMAL | 2021-07-22T21:56:15.332527+00:00 | 2021-07-22T21:56:15.332562+00:00 | 211 | false | ```\nint snakesAndLadders(vector<vector<int>>& board) {\n int R = board.size();\n int C = board[0].size(); \n int dest = R * C;\n queue<pair<int, int>> q;\n bool *visited = new bool[R*C + 1]{false};\n \n q.push({1, 0});\n visited[1] = true;\n \n ... | 3 | 0 | [] | 0 |
snakes-and-ladders | [C++] BFS solution with comments | c-bfs-solution-with-comments-by-ankitsha-etui | \n\nclass Solution {\npublic:\n array<int, 2> getCoordinates(int s, int n) {\n int row = n-1-(s-1)/n; //we divide the number by board size and su | ankitsharma99 | NORMAL | 2021-06-29T11:17:13.508236+00:00 | 2021-06-29T11:17:13.508266+00:00 | 350 | false | \n```\nclass Solution {\npublic:\n array<int, 2> getCoordinates(int s, int n) {\n int row = n-1-(s-1)/n; //we divide the number by board size and subtract with board size and 1 (as it is 0 indexed)\n int col = (s-1)%n;\n if((n%2 == 0 and row%2 == 0) or (n%2 == 1 and row%2 == 1) ) //sim... | 3 | 0 | [] | 0 |
snakes-and-ladders | c++ BFS, Convert 2D array into 1D array then solve | c-bfs-convert-2d-array-into-1d-array-the-ijcr | \n\nclass Solution {\npublic:\n int snakesAndLadders(vector<vector<int>>& board) {\n int n=board.size();\n int size=n*n;\n //cout<<size; | hemu22 | NORMAL | 2021-06-04T08:42:33.014243+00:00 | 2021-06-04T08:42:33.014271+00:00 | 295 | false | ```\n\nclass Solution {\npublic:\n int snakesAndLadders(vector<vector<int>>& board) {\n int n=board.size();\n int size=n*n;\n //cout<<size;\n vector<int>sl(size+1,-1);\n vector<bool>visited(size+1,0);\n int temp=1;\n bool toggle=1;\n for(int i=n-1;i>=0;i--){\n ... | 3 | 0 | [] | 0 |
snakes-and-ladders | [Java] BFS solution | java-bfs-solution-by-roka-9rht | \nclass Solution {\n public int snakesAndLadders(int[][] board) {\n int n = board.length;\n boolean[] visited = new boolean[n * n + 1];\n | roka | NORMAL | 2020-09-25T19:22:09.807182+00:00 | 2020-09-25T19:22:09.807216+00:00 | 175 | false | ```\nclass Solution {\n public int snakesAndLadders(int[][] board) {\n int n = board.length;\n boolean[] visited = new boolean[n * n + 1];\n Queue<Integer> queue = new LinkedList<>();\n \n queue.add(1);\n visited[1] = true;\n \n for (int counter = 0; !queue.isE... | 3 | 0 | [] | 0 |
snakes-and-ladders | Python 3 - faster than 98%, supposedly... | python-3-faster-than-98-supposedly-by-ke-zmx2 | get all the "portals" (snakes, ladders) -- no headache of jumping around the grid when a "position" tracker works just as well\n2. BFS for each dice roll on eac | kehaarable | NORMAL | 2020-04-20T23:51:30.164674+00:00 | 2020-04-20T23:51:30.164709+00:00 | 793 | false | 1. get all the "portals" (snakes, ladders) -- no headache of jumping around the grid when a "position" tracker works just as well\n2. BFS for each dice roll on each turn.\n\n```from collections import deque\n\nclass Solution:\n def snakesAndLadders(self, board: List[List[int]]) -> int:\n # makes the everythin... | 3 | 0 | ['Python3'] | 1 |
snakes-and-ladders | Dijkstra | dijkstra-by-sean72kimo-dfdt | Dijkstra\n\n\nclass Solution_dijkstra(object):\n\n def snakesAndLadders(self, board):\n """\n :type board: List[List[int]]\n :rtype: int | sean72kimo | NORMAL | 2019-07-05T23:25:57.944328+00:00 | 2019-07-05T23:25:57.944382+00:00 | 444 | false | Dijkstra\n\n```\nclass Solution_dijkstra(object):\n\n def snakesAndLadders(self, board):\n """\n :type board: List[List[int]]\n :rtype: int\n """\n if len(board) == 0:\n return 0\n n = len(board)\n nn = n * n\n arr = [0]\n for i, row in enumer... | 3 | 0 | [] | 1 |
snakes-and-ladders | ✅✅ Using BFS || Beginner Friendly || Easy Solution | using-bfs-beginner-friendly-easy-solutio-8rki | IntuitionThis problem is a variation of the shortest path problem in an unweighted graph. We can think of each cell in the board as a node, and moving from one | Karan_Aggarwal | NORMAL | 2025-03-06T12:49:15.539402+00:00 | 2025-03-06T12:49:15.539402+00:00 | 156 | false | ## Intuition
This problem is a variation of the **shortest path problem** in an **unweighted graph**. We can think of each cell in the board as a **node**, and moving from one cell to another (by rolling the dice) as an **edge**.
We need to find the **minimum number of moves** required to reach the last cell **(n × n)... | 2 | 0 | ['Array', 'Breadth-First Search', 'Matrix', 'C++'] | 0 |
snakes-and-ladders | Simple BFS | Python | simple-bfs-python-by-ov8cfej3su-gg94 | A nice optimization we can apply is to "unroll" the board into a
one dimensional array, indexed according to the board's square numbers. That way the square num | Ov8CfeJ3Su | NORMAL | 2025-03-04T03:29:55.177376+00:00 | 2025-03-04T03:29:55.177376+00:00 | 348 | false | 
A nice optimization we can apply is to "unroll" the board into a
one dimensional array, indexed according to the board's square numbers. That way the square numbers are easy to translate into board indices... | 2 | 0 | ['Breadth-First Search', 'Python3'] | 0 |
snakes-and-ladders | 100% beats using BFS traversal | 100-beats-using-bfs-traversal-by-tarunsi-nreo | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | tarunsingh04 | NORMAL | 2025-02-09T16:48:01.802240+00:00 | 2025-02-09T16:48:01.802240+00:00 | 234 | 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
`... | 2 | 0 | ['C++'] | 1 |
snakes-and-ladders | Java | clean code | BFS | Beats 92.40% | java-clean-code-bfs-beats-9240-by-user16-md06 | IntuitionApproach
step-1: flatten board
step-2: bfs (level order maintain distance from root)
step-3: return distance on reaching n^2
Complexity
Time complexity | Any_ | NORMAL | 2025-01-04T10:49:17.210783+00:00 | 2025-01-04T10:49:17.210783+00:00 | 437 | false | 
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
- step-1: flatten board
- step-2: bfs (level order mainta... | 2 | 0 | ['Array', 'Breadth-First Search', 'Matrix', 'Java'] | 0 |
snakes-and-ladders | Python BFS beats 99% | python-bfs-beats-99-by-darthvaper00-kt3a | Code\n```\nclass Solution:\n def snakesAndLadders(self, board: List[List[int]]) -> int:\n \n def calculate_position(r, c, n):\n maxN | darthvaper00 | NORMAL | 2024-03-18T06:00:55.930092+00:00 | 2024-03-18T06:00:55.930127+00:00 | 515 | false | # Code\n```\nclass Solution:\n def snakesAndLadders(self, board: List[List[int]]) -> int:\n \n def calculate_position(r, c, n):\n maxNumber = n**2 - r*n\n row = n - r - 1\n\n if row % 2 == 0: #ascending\n position = maxNumber - (n - c - 1)\n el... | 2 | 0 | ['Python3'] | 2 |
snakes-and-ladders | BFS Solution | Explained | bfs-solution-explained-by-singhsauravsk-wcyq | Intuition\nThe main idea behind the solution is to model the board as a graph, where each square is a node, and an edge between two nodes indicates a possible m | singhsauravsk | NORMAL | 2024-02-10T14:14:26.634789+00:00 | 2024-02-10T14:14:26.634821+00:00 | 236 | false | # Intuition\nThe main idea behind the solution is to model the board as a graph, where each square is a node, and an edge between two nodes indicates a possible move. The BFS algorithm is used to find the shortest path from the first square to the last square.\n\n# Key Points\n* **Graph Representation**: The game board... | 2 | 0 | ['Breadth-First Search', 'Java'] | 0 |
snakes-and-ladders | Easy Bfs Approach 10 ms solution | easy-bfs-approach-10-ms-solution-by-sand-g6ac | 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 | SandeepIlla | NORMAL | 2024-02-04T10:36:06.849564+00:00 | 2024-02-04T10:36:06.849607+00:00 | 205 | 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 | ['C++'] | 0 |
snakes-and-ladders | C++ BFS with queue simple solution -- beats 98,2 % | c-bfs-with-queue-simple-solution-beats-9-yh84 | Intuition\nThe problem asks for the minimum moves to reach the end, suggesting the use of a BFS algorithm\n\n# Approach\nThere are only 2 particularities:\n - c | rpunet | NORMAL | 2023-12-24T18:31:22.139914+00:00 | 2023-12-24T18:31:22.139945+00:00 | 124 | false | # Intuition\nThe problem asks for the minimum moves to reach the end, suggesting the use of a BFS algorithm\n\n# Approach\nThere are only 2 particularities:\n - convert the Boustrophedon matrix into a sequence array (g), in which we store the destination of the snake/ladder or -1, ie: g[3] = 23, meaning that in cell 3 ... | 2 | 0 | ['Breadth-First Search', 'Queue', 'C++'] | 1 |
snakes-and-ladders | C++ Simple solution || BFS || Queue | c-simple-solution-bfs-queue-by-samarpan2-f0p1 | Intuition\n Describe your first thoughts on how to solve this problem. \nUsing BFS algorithm to find smallest path\n# Approach\n Describe your approach to solvi | Samarpan27 | NORMAL | 2023-08-09T11:10:21.742381+00:00 | 2023-08-09T11:10:21.742405+00:00 | 24 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nUsing BFS algorithm to find smallest path\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe use box no. to access each index of matrix. We used an vis boolean array which shows whether that index is visited or not.\... | 2 | 0 | ['Breadth-First Search', 'Queue', 'Matrix', 'C++'] | 0 |
snakes-and-ladders | Python BFS | python-bfs-by-ayushgx-h1y7 | \nclass Solution:\n def snakesAndLadders(self, board: List[List[int]]) -> int:\n n = len(board)\n jumps, target = {}, n * n\n\n board.re | ayushgx | NORMAL | 2023-07-19T22:08:17.320613+00:00 | 2023-07-19T22:08:17.320669+00:00 | 285 | false | ```\nclass Solution:\n def snakesAndLadders(self, board: List[List[int]]) -> int:\n n = len(board)\n jumps, target = {}, n * n\n\n board.reverse()\n for i in range(n): board[i].reverse() if i % 2 else None\n\n c = 0\n for i in board:\n for j in i:\n ... | 2 | 0 | ['Array', 'Breadth-First Search', 'Matrix', 'Python3'] | 0 |
snakes-and-ladders | 🐍 python, simple BFS solution with explanation; O(n) | python-simple-bfs-solution-with-explanat-egcc | Intuition\nIt is a a bit messy BFS problem. \n\n# Approach\n1) As you can see the board is 2D but the the order of the cells can be a represented as a one-dimen | smvthirteen | NORMAL | 2023-07-16T01:32:45.164347+00:00 | 2023-07-16T20:31:36.871816+00:00 | 163 | false | # Intuition\nIt is a a bit messy BFS problem. \n\n# Approach\n1) As you can see the board is 2D but the the order of the cells can be a represented as a one-dimensional array. Also, the columns reverse every other row and the cells start at 1 not zero. Considering all of that, we need a mapping array: `array[i]=(row_i,... | 2 | 0 | ['Array', 'Breadth-First Search', 'Graph', 'Matrix', 'Python3'] | 0 |
snakes-and-ladders | Explained python3 BFS solution | explained-python3-bfs-solution-by-shrish-3yie | Intuition\n Describe your first thoughts on how to solve this problem. \nUse BFS\n\n# Approach\n Describe your approach to solving the problem. \nThe conversion | shrishtikarkera | NORMAL | 2023-07-15T17:43:01.202412+00:00 | 2023-07-15T17:43:01.202452+00:00 | 57 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nUse BFS\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThe conversion from the position of the board in cell number to the actual coordinate in the board array is an important one. Identifying the row is easy --> ... | 2 | 0 | ['Python3'] | 0 |
snakes-and-ladders | Reason why DFS won't work in some testcases. | reason-why-dfs-wont-work-in-some-testcas-haxr | \n# Approach\nIn this article, I will explain the reason behind DFS (with DP optimization) approach not working.\n\n# Reason\nDFS Approach would work perfectly | brickcommander | NORMAL | 2023-01-25T15:14:39.018018+00:00 | 2023-01-25T15:14:39.018065+00:00 | 249 | false | \n# Approach\nIn this article, I will explain the reason behind DFS (with DP optimization) approach not working.\n\n# Reason\nDFS Approach would work perfectly fine if the graph is acylic but here the graph could be cyclic as well.\nExample of cyclic graph:\n {\n int pos[26] = {};\n for (int i = 0; i < s.size(); ++i) {\n | votrubac | NORMAL | 2022-09-04T04:00:59.601138+00:00 | 2022-09-04T21:00:34.106887+00:00 | 3,708 | false | #### Track First Position\n**C++**\n```cpp\nbool checkDistances(string s, vector<int>& distance) {\n int pos[26] = {};\n for (int i = 0; i < s.size(); ++i) {\n int n = s[i] - \'a\';\n if (pos[n] > 0 && distance[n] != i - pos[n])\n return false;\n pos[n] = i + 1;\n }\n return ... | 42 | 0 | ['C', 'Java'] | 2 |
check-distances-between-same-letters | Python3 || 4 lines, dict, enumerate || T/S: 95% / 100% | python3-4-lines-dict-enumerate-ts-95-100-dbb8 | \nclass Solution:\n def checkDistances(self, s: str, distance: List[int]) -> bool:\n \n d = defaultdict(list)\n\n for i, ch in enumerate | Spaulding_ | NORMAL | 2024-03-05T18:33:05.999904+00:00 | 2024-06-14T16:17:48.385974+00:00 | 559 | false | ```\nclass Solution:\n def checkDistances(self, s: str, distance: List[int]) -> bool:\n \n d = defaultdict(list)\n\n for i, ch in enumerate(s):\n d[ch].append(i)\n\n return all(b-a-1 == distance[ord(ch)-97] for ch, (a,b) in d.items()\n```\n[https://leetcode.com/problems/check-d... | 16 | 0 | ['Python3'] | 0 |
check-distances-between-same-letters | ⭐ HashMap || Explained || Beginner Friendly | hashmap-explained-beginner-friendly-by-c-yekc | \n/*\nUse map to store the character and the index of its first occurance\nAnd when the second occurance found, count the elemnets in between\nand check in dist | coder481 | NORMAL | 2022-09-04T04:01:48.642025+00:00 | 2022-09-04T04:01:48.642058+00:00 | 1,305 | false | ```\n/*\nUse map to store the character and the index of its first occurance\nAnd when the second occurance found, count the elemnets in between\nand check in distance[] whether the distance at the place is correct or not\n*/\nclass Solution {\n public boolean checkDistances(String s, int[] distance) {\n \n ... | 14 | 1 | ['Java'] | 1 |
check-distances-between-same-letters | Last position [C++/Java] | last-position-cjava-by-xxvvpp-yh9g | null | xxvvpp | NORMAL | 2022-09-04T04:02:53.804875+00:00 | 2022-09-04T04:48:33.153339+00:00 | 1,924 | false | <iframe src="https://leetcode.com/playground/CRM7QX8D/shared" frameBorder="0" width="800" height="300"></iframe> | 10 | 0 | ['C', 'Java'] | 1 |
check-distances-between-same-letters | ✅ C++ | | Map || Easy to understand | c-map-easy-to-understand-by-indresh149-ey07 | \nclass Solution {\npublic:\n bool checkDistances(string s, vector<int>& distance) {\n map<char, vector<int>> mpp;\n\n for (int i = 0; i < s.si | indresh149 | NORMAL | 2022-09-04T04:01:21.391891+00:00 | 2022-09-04T04:01:21.391943+00:00 | 1,353 | false | ```\nclass Solution {\npublic:\n bool checkDistances(string s, vector<int>& distance) {\n map<char, vector<int>> mpp;\n\n for (int i = 0; i < s.size(); i++){\n mpp[s[i]].push_back(i);\n }\n\n for (auto it : mpp)\n { \n if (it.second[1] - it.second[0] - 1 !=... | 10 | 1 | ['C'] | 2 |
check-distances-between-same-letters | Python | 98% Faster | Easy Solution✅ | python-98-faster-easy-solution-by-gmanay-4xw0 | \ndef checkDistances(self, s: str, distance: List[int]) -> bool:\n unique = set(s)\n for letter in unique:\n index = s.index(letter) # | gmanayath | NORMAL | 2022-09-07T12:28:32.129060+00:00 | 2022-12-22T16:44:29.538597+00:00 | 1,343 | false | ```\ndef checkDistances(self, s: str, distance: List[int]) -> bool:\n unique = set(s)\n for letter in unique:\n index = s.index(letter) # get the first index of the letter\n dis = distance[ord(letter)-97]\n if index+dis+1 > len(s)-1 or s[index+dis+1] != letter:\n ... | 9 | 0 | ['Python', 'Python3'] | 1 |
check-distances-between-same-letters | Easy Java Solution || Map | easy-java-solution-map-by-devkd-uxc7 | Check Distances Between Same Letters\n\nApproach:\n1.) We iterate over the String and create a hashmap\n2.) While iterating if the character is not in hashmap, | DevKD | NORMAL | 2022-09-04T04:12:40.729170+00:00 | 2022-09-04T04:12:40.729221+00:00 | 854 | false | # **Check Distances Between Same Letters**\n\n**Approach:**\n1.) We iterate over the String and create a hashmap\n2.) While iterating if the character is not in hashmap, we put it in hashmap\n3.) If character is in hashmap we compute the number of letter between the two occurences by cuurIndex-ma.get(char)-1 and check ... | 7 | 0 | ['Java'] | 0 |
check-distances-between-same-letters | ✅ C++ | Easy | Self Explanatory | BruteForce | c-easy-self-explanatory-bruteforce-by-ra-rkv8 | Do UPVOTE if it helps :)\n\nbool checkDistances(string s, vector<int>& distance) {\n int n =s.length();\n for(int i=0;i<n;i++)\n for(in | raunak__pandey | NORMAL | 2022-09-04T04:00:35.542872+00:00 | 2022-09-04T05:06:59.708832+00:00 | 795 | false | **Do UPVOTE if it helps :)**\n```\nbool checkDistances(string s, vector<int>& distance) {\n int n =s.length();\n for(int i=0;i<n;i++)\n for(int j=i+1;j<n;j++)\n if(s[i]==s[j])\n if(j-i-1 != distance[s[i]-\'a\']) return false;\n return true;\n }\n``` | 7 | 1 | ['C', 'C++'] | 1 |
check-distances-between-same-letters | Easy Brute force approach in C++ | easy-brute-force-approach-in-c-by-krishn-mqch | Intuition\n Describe your first thoughts on how to solve this problem. \nOverall, this solution has a time complexity of O(n^2), where n is the length of the in | Krishnaroy7 | NORMAL | 2023-04-11T20:17:09.401829+00:00 | 2023-04-11T20:17:33.101711+00:00 | 691 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nOverall, this solution has a time complexity of O(n^2), where n is the length of the input string. This may not be efficient for very large input strings, but it is a straightforward approach to solve this problem.\n\n# Approach\n<!-- Des... | 6 | 0 | ['C++'] | 1 |
check-distances-between-same-letters | Beginner friendly [Java/JavaScript/Python] Solution | beginner-friendly-javajavascriptpython-s-nn5b | Time Complexity : O(n)\nJava\n\nclass Solution {\n public boolean checkDistances(String s, int[] distance) {\n int[] arr = new int[26];\n for(i | HimanshuBhoir | NORMAL | 2022-09-10T02:08:21.061912+00:00 | 2022-09-10T02:13:57.442580+00:00 | 1,309 | false | **Time Complexity : O(n)**\n**Java**\n```\nclass Solution {\n public boolean checkDistances(String s, int[] distance) {\n int[] arr = new int[26];\n for(int i=0; i<s.length(); i++){\n if(arr[s.charAt(i) - \'a\'] != 0 && i - arr[s.charAt(i) - \'a\'] != distance[s.charAt(i) - \'a\']) \n ... | 6 | 0 | ['Python', 'Java', 'JavaScript'] | 2 |
check-distances-between-same-letters | Python Dictionary || Easy to understand | python-dictionary-easy-to-understand-by-q42ol | \nclass Solution:\n def checkDistances(self, s: str, distance: List[int]) -> bool: \n hashmap = {}\n for i in range(len(s)):\n | fight2023 | NORMAL | 2022-09-04T04:49:08.630264+00:00 | 2022-09-05T01:16:47.441180+00:00 | 1,105 | false | ```\nclass Solution:\n def checkDistances(self, s: str, distance: List[int]) -> bool: \n hashmap = {}\n for i in range(len(s)):\n if s[i] in hashmap and i - hashmap[s[i]] - 1 != distance[ord(s[i]) - ord(\'a\')]:\n return False\n hashmap[s[i]] = i ... | 6 | 0 | ['Python', 'Python3'] | 0 |
check-distances-between-same-letters | Beginner O(N^2) and Linear solution with explanation | beginner-on2-and-linear-solution-with-ex-nnxe | O(N^2) Approach: For each character s[i], check for all other characters s[j] where j ranges from i+1 to n. Compare the distance when i th and j th character is | shubhamsth | NORMAL | 2022-09-04T04:48:20.523668+00:00 | 2022-09-04T05:12:25.521289+00:00 | 521 | false | **O(N^2) Approach:** For each character `s[i]`, check for all other characters `s[j]` where `j` ranges from `i+1` to `n`. Compare the distance when `i th` and `j th` character is same.\n```\nbool checkDistances(string s, vector<int>& dist) {\n\tint n = s.size();\n\tfor(int i=0; i<n-1; i++)\n\t\tfor(int j=i+1; j<n; j++)... | 6 | 0 | ['C'] | 0 |
check-distances-between-same-letters | CPP | Easy | cpp-easy-by-amirkpatna-0a06 | \nclass Solution {\npublic:\n bool checkDistances(string s, vector<int>& distance) {\n vector<int> v(26);\n int i=0;\n for(char c:s){\n | amirkpatna | NORMAL | 2022-09-04T04:08:26.272057+00:00 | 2022-09-04T04:08:26.272081+00:00 | 648 | false | ```\nclass Solution {\npublic:\n bool checkDistances(string s, vector<int>& distance) {\n vector<int> v(26);\n int i=0;\n for(char c:s){\n if(v[c-\'a\'] && distance[c-\'a\']!=i-v[c-\'a\'])return false;\n v[c-\'a\']=++i;\n }\n return true;\n }\n};\n``` | 6 | 0 | ['C++'] | 0 |
check-distances-between-same-letters | Simple java solution | simple-java-solution-by-siddhant_1602-qpsk | ```\nclass Solution {\n public boolean checkDistances(String s, int[] d) {\n for(int i=0;i<26;i++)\n {\n char c = (char)(\'a\'+i);\n | Siddhant_1602 | NORMAL | 2022-09-04T04:01:09.632620+00:00 | 2022-09-04T04:01:09.632660+00:00 | 597 | false | ```\nclass Solution {\n public boolean checkDistances(String s, int[] d) {\n for(int i=0;i<26;i++)\n {\n char c = (char)(\'a\'+i);\n if(s.contains(String.valueOf(c)))\n {\n int k = s.indexOf(c);\n int p = s.lastIndexOf(c);\n ... | 6 | 1 | ['String', 'Java'] | 0 |
check-distances-between-same-letters | C++ | two-pointers | c-two-pointers-by-parwez01-ydf9 | if you get the both position,\n1. calculate distance\n2. check if distance is equal in distance array.\n3. if not return false\n4. if yes mark as those elements | parwez01 | NORMAL | 2022-09-04T04:06:43.518491+00:00 | 2022-09-04T04:06:43.518526+00:00 | 81 | false | if you get the both position,\n1. calculate distance\n2. check if distance is equal in distance array.\n3. if not return false\n4. if yes mark as those elements are visited.\n\nsimple intitutioin behind this questin.\n\n```\nclass Solution {\npublic:\n bool checkDistances(string s, vector<int>& distance) {\n ... | 5 | 0 | ['Two Pointers', 'C'] | 0 |
check-distances-between-same-letters | ✅3 Method's || C++ || JAVA || PYTHON || Beginner Friendly🔥🔥🔥 | 3-methods-c-java-python-beginner-friendl-ha9v | Intuition\n Describe your first thoughts on how to solve this problem. \nThe "Check Distances Between Same Letters" problem involves validating if the distance | datpham0412 | NORMAL | 2024-04-21T04:46:22.903939+00:00 | 2024-04-21T04:46:22.903964+00:00 | 307 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe "Check Distances Between Same Letters" problem involves validating if the distance between each pair of identical letters in a string matches a specified value. This problem tests our ability to efficiently track positions and calcula... | 4 | 0 | ['Array', 'Hash Table', 'C++', 'Java', 'Python3'] | 1 |
check-distances-between-same-letters | Easy and Simple Python Solution | easy-and-simple-python-solution-by-sanga-z85b | \nclass Solution:\n def checkDistances(self, s: str, distance: List[int]) -> bool:\n dic={}\n letter=97\n for i in distance:\n | sangam92 | NORMAL | 2022-10-06T06:02:23.417625+00:00 | 2022-10-06T06:03:06.551234+00:00 | 861 | false | ```\nclass Solution:\n def checkDistances(self, s: str, distance: List[int]) -> bool:\n dic={}\n letter=97\n for i in distance:\n dic[chr(letter)]=i\n letter+=1\n\n for i in set(s):\n first=s.index(i)\n last=s.rindex(i)\n diff=last-fi... | 4 | 0 | ['Python'] | 0 |
check-distances-between-same-letters | c++ solution||constant space | c-solutionconstant-space-by-anvitha1221-l6mz | \n\nclass Solution {\npublic:\n bool checkDistances(string s, vector<int>& distance) {\n int n=s.length();\n for(int i=0;i<n;i++){\n if(dist | anvitha1221 | NORMAL | 2022-09-04T05:02:36.992460+00:00 | 2022-09-04T05:04:05.716778+00:00 | 161 | false | ```\n\nclass Solution {\npublic:\n bool checkDistances(string s, vector<int>& distance) {\n int n=s.length();\n for(int i=0;i<n;i++){\n if(distance[s[i]-\'a\']==-1){\n\t\t//marked as not valid in the previous visit so return false \n return false;\n }\n \n \n ... | 4 | 0 | ['C'] | 0 |
check-distances-between-same-letters | please read the note mentioned in test case 1 ho jayega easy hee hai kar har maidan fateh !!! :D | please-read-the-note-mentioned-in-test-c-a9r2 | 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 | yesyesem | NORMAL | 2024-09-01T19:30:06.334670+00:00 | 2024-09-01T19:30:06.334695+00:00 | 30 | 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 | ['C++'] | 0 |
check-distances-between-same-letters | Rust | O(n) | 1ms | rust-on-1ms-by-user7454af-ftl0 | Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(1)\n\n# Code\n\nimpl Solution {\n pub fn check_distances(s: String, mut distance: Vec<i32>) -> b | user7454af | NORMAL | 2024-06-23T21:28:25.323517+00:00 | 2024-06-23T21:28:25.323548+00:00 | 11 | false | # Complexity\n- Time complexity: $$O(n)$$\n\n- Space complexity: $$O(1)$$\n\n# Code\n```\nimpl Solution {\n pub fn check_distances(s: String, mut distance: Vec<i32>) -> bool {\n let sb = s.into_bytes();\n for (i, &b) in sb.iter().enumerate() {\n match distance[(b-b\'a\') as usize] {\n ... | 3 | 0 | ['Rust'] | 0 |
check-distances-between-same-letters | ✔✔✔💯% beats in runtime. Beginner friendly solution. | beats-in-runtime-beginner-friendly-solut-cubs | 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 | hikmatulloanvarbekov001 | NORMAL | 2023-07-20T15:21:39.275862+00:00 | 2023-07-20T15:21:39.275883+00:00 | 184 | 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 | ['Java'] | 2 |
check-distances-between-same-letters | ✅✅✅100% faster python solution. | 100-faster-python-solution-by-najmiddin1-j6i4 | \n\n- In the loop, we need to find and divide the index of the next letter of the letter s[i], and if the difference between these two values is not equal to ea | Najmiddin1 | NORMAL | 2022-12-17T09:10:44.414489+00:00 | 2022-12-17T09:10:44.414531+00:00 | 704 | false | \n\n- In the loop, we need to find and divide the index of the next letter of the letter `s[i]`, and if the difference between these two values is not equal to each other, then we... | 3 | 0 | ['Python', 'Python3'] | 0 |
check-distances-between-same-letters | C++ || keep an index of the first occurrence || clean code || easy to understand || fast (0ms) | c-keep-an-index-of-the-first-occurrence-r6jhx | Solution 1: keep an index of the first occurrence\n\nWe actually keep track of the first occurrence plus one, with that we can just initialize the index with ze | heder | NORMAL | 2022-09-04T14:40:51.425438+00:00 | 2022-09-04T14:40:51.425476+00:00 | 227 | false | ### Solution 1: keep an index of the first occurrence\n\nWe actually keep track of the first occurrence plus one, with that we can just initialize the index with zeros and we would need to substract this one when checking the distance anyway. We are using an ```array<>``` here as it has less overhead than ```vector```.... | 3 | 0 | ['C'] | 0 |
check-distances-between-same-letters | Easy solution using string functions | easy-solution-using-string-functions-by-djimz | class Solution {\npublic:\n bool checkDistances(string s, vector& v) {\n \n int n=26;\n for(int i=0;i<26;i++)\n {\n in | aryanshsingla | NORMAL | 2022-09-04T12:23:43.506687+00:00 | 2022-09-04T12:24:53.389672+00:00 | 101 | false | class Solution {\npublic:\n bool checkDistances(string s, vector<int>& v) {\n \n int n=26;\n for(int i=0;i<26;i++)\n {\n int t=97+i;\n char ch=t;\n int x=s.find(t);\n int y=s.rfind(t);\n if(y==-1)continue;\n if((y-x-1)!=v[i... | 3 | 0 | ['C'] | 0 |
check-distances-between-same-letters | c++ | Faster than 100% | Two Approaches | c-faster-than-100-two-approaches-by-theo-7z4v | To get index of distance for current string element, we need to substract \n\t\tcurr element from \'a\'.\n\t\t cur = a, it\'s corresponding distance index == a | theomkumar | NORMAL | 2022-09-04T05:09:31.491308+00:00 | 2022-09-04T05:09:31.491344+00:00 | 587 | false | To get index of distance for current string element, we need to substract \n\t\tcurr element from \'a\'.\n\t\t* cur = a, it\'s corresponding distance index == a - a = 0\n\t\t* cur = b, b - a = 1\n\t\t* cur = c, c - a = 2\n\nApproach 1: SC -> O(1)\n\t \n ```\nbool checkDistances(string s, vector<int>& distance) {\n ... | 3 | 0 | ['C', 'C++'] | 0 |
check-distances-between-same-letters | ✅ JavaScript | Map | TC O(n) | SC O(n) | javascript-map-tc-on-sc-on-by-thakurball-29gb | \n/**\n * @param {string} s\n * @param {number[]} distance\n * @return {boolean}\n */\nvar checkDistances = function(s, distance) {\n const map = {};\n \n | thakurballary | NORMAL | 2022-09-04T04:02:56.169189+00:00 | 2022-09-04T04:02:56.169238+00:00 | 348 | false | ```\n/**\n * @param {string} s\n * @param {number[]} distance\n * @return {boolean}\n */\nvar checkDistances = function(s, distance) {\n const map = {};\n \n for (let i = 0; i < s.length; i++) {\n if (map[s[i]] !== undefined) {\n const diff = i - map[s[i]] - 1;\n const charCode = s... | 3 | 0 | ['JavaScript'] | 1 |
check-distances-between-same-letters | Find left and right index | Explained | find-left-and-right-index-explained-by-n-67wi | We know that there are only 2 occurences of the same character in S if it exists.\nAnd it must be distanced distance[char] from each other.\n\nWe can find the i | nadaralp | NORMAL | 2022-09-04T04:01:13.260232+00:00 | 2022-09-04T04:01:13.260272+00:00 | 434 | false | We know that there are only 2 occurences of the same character in S if it exists.\nAnd it must be distanced distance[char] from each other.\n\nWe can find the index on the left and right side and check whether the distance is distance[char].\nIf the character doesn\'t exist we ignore.\n\n```\nclass Solution:\n def c... | 3 | 0 | ['Python'] | 0 |
check-distances-between-same-letters | Java solution || Beats 99% || easy explanation | java-solution-beats-99-easy-explanation-d59ui | \n# Approach\n Describe your approach to solving the problem. \n\n\n1. It initializes a HashMap called map to keep track of the last index at which each charact | akanksha41 | NORMAL | 2023-10-20T12:20:10.209158+00:00 | 2023-10-20T12:20:10.209176+00:00 | 185 | false | \n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n\n1. It initializes a `HashMap` called `map` to keep track of the last index at which each character appears in the string.\n\n2. It iterates through each character in the input string `s` using a for loop.\n\n3. For each character `ch`, it checks... | 2 | 0 | ['Array', 'Hash Table', 'String', 'Java'] | 0 |
check-distances-between-same-letters | Check Distance Between Same Letters | check-distance-between-same-letters-by-a-srfm | \n\n# Code\n\nclass Solution {\npublic:\n bool checkDistances(string s, vector<int>& distance) {\n int val=0;\n for(int i=0;i<s.size();i++)\n | AbhayDabral17 | NORMAL | 2023-06-20T20:24:31.918216+00:00 | 2023-06-20T20:24:31.918239+00:00 | 71 | false | \n\n# Code\n```\nclass Solution {\npublic:\n bool checkDistances(string s, vector<int>& distance) {\n int val=0;\n for(int i=0;i<s.size();i++)\n {\n for(int j=i+1;j<s.size();j++)\n {\n if(s[j]==s[i])\n {\n val=(int)s[i]-97;\... | 2 | 0 | ['C++'] | 0 |
check-distances-between-same-letters | [Java] Simple O(n) solution | java-simple-on-solution-by-ytchouar-isrk | java\nclass Solution {\n public boolean checkDistances(String s, int[] distance) {\n int[] range = new int[distance.length];\n Arrays.fill(rang | YTchouar | NORMAL | 2023-05-02T22:24:45.664530+00:00 | 2023-05-02T22:24:45.664566+00:00 | 581 | false | ```java\nclass Solution {\n public boolean checkDistances(String s, int[] distance) {\n int[] range = new int[distance.length];\n Arrays.fill(range, -1);\n\n for(int i = 0; i < s.length(); ++i) {\n int index = s.charAt(i) - \'a\';\n\n if(range[index] != -1 && Math.abs(range... | 2 | 0 | ['Java'] | 1 |
check-distances-between-same-letters | Easy C++ Solution using hashmaps | easy-c-solution-using-hashmaps-by-reehan-8fof | Intuition\nOur goal is to check if the given string s is well-spaced according to the given distances. We will iterate through the string and record the first a | Reehan9 | NORMAL | 2023-04-04T05:31:44.244682+00:00 | 2023-04-04T05:31:44.244712+00:00 | 470 | false | # Intuition\nOur goal is to check if the given string s is well-spaced according to the given distances. We will iterate through the string and record the first and second occurrences of each character. Then, we will compare the recorded distances to the given distance vector to determine if the string is well-spaced.\... | 2 | 0 | ['C++'] | 2 |
check-distances-between-same-letters | Python3 easy solution | python3-easy-solution-by-amitpandit03-6jbh | \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. O(n) \n | amitpandit03 | NORMAL | 2023-03-10T22:34:48.741129+00:00 | 2023-03-10T22:34:48.741162+00:00 | 322 | false | \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. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n def checkDistances(self, s: str, dis: List[int]) -> bool:\n d = {}\n for i in range(len(... | 2 | 0 | ['Array', 'Hash Table', 'String', 'Python3'] | 0 |
check-distances-between-same-letters | JS very easy solution with O(n) | js-very-easy-solution-with-on-by-kunkka1-in4g | Code\n\n/**\n * @param {string} s\n * @param {number[]} distance\n * @return {boolean}\n */\nvar checkDistances = function(s, distance) {\n const hashmap = n | kunkka1996 | NORMAL | 2022-11-04T07:18:06.651131+00:00 | 2022-11-04T07:18:06.651198+00:00 | 543 | false | # Code\n```\n/**\n * @param {string} s\n * @param {number[]} distance\n * @return {boolean}\n */\nvar checkDistances = function(s, distance) {\n const hashmap = new Map();\n\n for (let i = 0; i < s.length; i++) {\n const character = s[i];\n if (hashmap.has(character)) {\n if (i - hashmap.... | 2 | 0 | ['Hash Table', 'JavaScript'] | 0 |
check-distances-between-same-letters | [JAVA] 6 liner easy solution | java-6-liner-easy-solution-by-jugantar20-e6n6 | \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. O(n) \n | Jugantar2020 | NORMAL | 2022-11-04T06:15:23.378962+00:00 | 2022-11-04T06:15:23.379011+00:00 | 629 | false | \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. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n public boolean checkDistances(String s, int[] distance) {\n HashMap<Character, Integer> map = ne... | 2 | 0 | ['Java'] | 0 |
check-distances-between-same-letters | Easiest C++ Solution || O(n) solution || O(1) space | easiest-c-solution-on-solution-o1-space-kfnmx | \n# Code\n\nclass Solution {\npublic:\n bool checkDistances(string s, vector<int>& distance) {\n for(int i=0;i<s.length();i++){\n if(distan | Shristha | NORMAL | 2022-10-20T03:51:09.963944+00:00 | 2022-10-20T03:51:09.963984+00:00 | 901 | false | \n# Code\n```\nclass Solution {\npublic:\n bool checkDistances(string s, vector<int>& distance) {\n for(int i=0;i<s.length();i++){\n if(distance[s[i]-97]!=-1){\n int next=i+(distance[s[i]-97]+1);\n\n if((next>=s.length())||(next<s.length() && s[next]!=s[i])){\n ... | 2 | 0 | ['C++'] | 0 |
check-distances-between-same-letters | C++ Solution | Easy to understand | c-solution-easy-to-understand-by-shivi_0-6qms | \t**Please Upvote if you like my solution !!!! :)****\n\t\n\t unordered_mapmp;\n\t\t \n for(int i=0;i<s.size();i++)\n {\n \n if(mp. | shivi_071996 | NORMAL | 2022-10-06T07:12:39.079470+00:00 | 2022-10-20T03:35:05.227437+00:00 | 132 | false | \t******Please Upvote if you like my solution !!!! :)******\n\t\n\t unordered_map<int,int>mp;\n\t\t \n for(int i=0;i<s.size();i++)\n {\n \n if(mp.find(s[i]-\'a\')==mp.end())\n {\n mp[(s[i]-\'a\')]=i;\n }\n else\n {\n ... | 2 | 0 | [] | 0 |
check-distances-between-same-letters | Tracking first occurrences | tracking-first-occurrences-by-fllght-0463 | Java\njava\npublic boolean checkDistances(String s, int[] distance) {\n int[] firstOccurrences = new int[26];\n Arrays.fill(firstOccurrences, -1); | FLlGHT | NORMAL | 2022-10-05T14:34:56.946290+00:00 | 2022-10-05T14:35:11.226057+00:00 | 484 | false | ##### Java\n```java\npublic boolean checkDistances(String s, int[] distance) {\n int[] firstOccurrences = new int[26];\n Arrays.fill(firstOccurrences, -1);\n\n for (int i = 0; i < s.length(); ++i) {\n int letterNumber = s.charAt(i) - \'a\';\n if (firstOccurrences[letterNumber]... | 2 | 0 | ['C', 'Java'] | 0 |
check-distances-between-same-letters | Java using indexOf with comments | java-using-indexof-with-comments-by-pete-78l0 | \nclass Solution {\n public boolean checkDistances(String s, int[] distance) {\n // for each char in s to char array\n for (char c : s.toCharAr | peterTorres | NORMAL | 2022-10-01T18:29:45.049854+00:00 | 2022-10-01T18:29:45.049894+00:00 | 151 | false | ```\nclass Solution {\n public boolean checkDistances(String s, int[] distance) {\n // for each char in s to char array\n for (char c : s.toCharArray()) {\n // init first to s index of char\n int first = s.indexOf(c);\n // init second to s last index of char\n ... | 2 | 0 | ['Java'] | 0 |
check-distances-between-same-letters | C++ || Brute Force + Optimised Solution | c-brute-force-optimised-solution-by-kuma-8khf | Optimised Solution -:\nTime Complexity -> O(n)\nSpace Complexity -> O(1)\n\n\tbool checkDistances(string s, vector& distance) {\n\n\t\tunordered_map mpp;\n | kumarpawansahh | NORMAL | 2022-09-30T13:28:57.530141+00:00 | 2022-09-30T13:28:57.530176+00:00 | 297 | false | Optimised Solution -:\nTime Complexity -> O(n)\nSpace Complexity -> O(1)\n\n\tbool checkDistances(string s, vector<int>& distance) {\n\n\t\tunordered_map<char,int> mpp;\n \n for(int i=0;i<s.size();i++){\n if(mpp[s[i]]==0){\n mpp[s[i]]=i+1;\n }\n else{\n ... | 2 | 0 | ['Array', 'String'] | 1 |
check-distances-between-same-letters | Simple Python Solution | simple-python-solution-by-mediocre-coder-b1fq | \nclass Solution:\n def checkDistances(self, s: str, distance: List[int]) -> bool:\n visited = ""\n \n for alpha in s:\n if a | mediocre-coder | NORMAL | 2022-09-06T20:55:00.571899+00:00 | 2022-09-06T20:55:00.571938+00:00 | 105 | false | ```\nclass Solution:\n def checkDistances(self, s: str, distance: List[int]) -> bool:\n visited = ""\n \n for alpha in s:\n if alpha not in visited:\n visited += alpha\n if s.rindex(alpha) - s.index(alpha) - 1 != distance[ord(alpha) - 97]:\n ... | 2 | 0 | ['Python'] | 0 |
check-distances-between-same-letters | ✅ [TypeScript] 100%, one-pass & in-place solution (with detailed comments) | typescript-100-one-pass-in-place-solutio-5rum | This solution checks the correctness of distances in one pass by performing in-place operations. It demonstrated 59 ms runtime (100.00%) and used 45.1 MB memory | stanislav-iablokov | NORMAL | 2022-09-06T13:36:20.989460+00:00 | 2022-10-23T13:01:00.400729+00:00 | 45 | false | This [solution](https://leetcode.com/submissions/detail/793015446/) checks the correctness of distances in one pass by performing in-place operations. It demonstrated **59 ms runtime (100.00%)** and used **45.1 MB memory (70.59%)**. Detailed comments are provided.\n\n**IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE.**\n```\n... | 2 | 0 | ['TypeScript'] | 1 |
check-distances-between-same-letters | Simple solution keeps track of first and last position! | simple-solution-keeps-track-of-first-and-6b18 | Time complexity: O(N) length of the string\nSpace complexity: O(1) hashmap with constant length 26\n\nclass Solution {\npublic:\n bool checkDistances(string | YixingChen | NORMAL | 2022-09-04T22:00:10.230158+00:00 | 2022-09-04T22:00:10.230186+00:00 | 84 | false | Time complexity: O(N) length of the string\nSpace complexity: O(1) hashmap with constant length 26\n```\nclass Solution {\npublic:\n bool checkDistances(string s, vector<int>& distance) {\n unordered_map<int, vector<int>> hash(26);\n for (int i = 0; i < s.size(); ++ i) hash[s[i] - \'a\'].emplace_back(i... | 2 | 0 | [] | 0 |
check-distances-between-same-letters | C++ || Unordered Map || Easy Solution | c-unordered-map-easy-solution-by-vibrant-r1fx | \nbool checkDistances(string s, vector<int>& distance) {\n unordered_map<char,int>m;\n for(int i=0;i<s.length();i++){\n int j=s[i]-\'a\ | vibrant_CoDeR | NORMAL | 2022-09-04T11:57:56.929293+00:00 | 2022-09-04T11:57:56.929339+00:00 | 52 | false | ```\nbool checkDistances(string s, vector<int>& distance) {\n unordered_map<char,int>m;\n for(int i=0;i<s.length();i++){\n int j=s[i]-\'a\';\n if(m.find(s[i])==m.end())\n m.insert({s[i],i});\n else if(i-m[s[i]]-1!=distance[j])\n return false;\... | 2 | 0 | [] | 0 |
check-distances-between-same-letters | Python || iterative || Easy | python-iterative-easy-by-1md3nd-c840 | Simple approch\n## Time -> O(n^2) {n <= 32}\n## Space -> O(1)\n\nclass Solution:\n def checkDistances(self, s: str, distance: List[int]) -> bool:\n | 1md3nd | NORMAL | 2022-09-04T10:28:34.985648+00:00 | 2022-09-04T10:28:34.985693+00:00 | 203 | false | # Simple approch\n## Time -> O(n^2) {n <= 32}\n## Space -> O(1)\n```\nclass Solution:\n def checkDistances(self, s: str, distance: List[int]) -> bool:\n n = len(s)\n for i in range(n-1):\n for j in range(i+1,n):\n if s[i] == s[j]:\n if distance[ord(s[i]) -... | 2 | 0 | ['Iterator', 'Python', 'Python3'] | 0 |
check-distances-between-same-letters | Swift O(n) solution using HashMap | swift-on-solution-using-hashmap-by-andre-ng3p | \nclass Solution {\n func checkDistances(_ s: String, _ distance: [Int]) -> Bool {\n var lettersMap: [Character: Int] = [:]\n for (i, c) in s.e | AndreevIVdev | NORMAL | 2022-09-04T09:11:02.089345+00:00 | 2022-09-04T09:11:02.089386+00:00 | 56 | false | ```\nclass Solution {\n func checkDistances(_ s: String, _ distance: [Int]) -> Bool {\n var lettersMap: [Character: Int] = [:]\n for (i, c) in s.enumerated() {\n if let letter = lettersMap[c] {\n lettersMap[c] = i - letter - 1\n } else {\n lettersMap[... | 2 | 0 | ['Swift'] | 0 |
check-distances-between-same-letters | Java || Easy || Set || Linear Time Fast Solution | java-easy-set-linear-time-fast-solution-20ie4 | \nclass Solution {\n public boolean checkDistances(String s, int[] distance) {\n char[] str = s.toCharArray();\n boolean set[] = new boolean[26 | Lil_ToeTurtle | NORMAL | 2022-09-04T06:26:51.879252+00:00 | 2022-09-04T06:26:51.879298+00:00 | 297 | false | ```\nclass Solution {\n public boolean checkDistances(String s, int[] distance) {\n char[] str = s.toCharArray();\n boolean set[] = new boolean[26];\n Integer start[] = new Integer[26],end[] = new Integer[26];\n int i,j,res,n=str.length,ind;\n for(i=0;i<n;i++){\n ind = s... | 2 | 0 | ['Java'] | 1 |
check-distances-between-same-letters | C++ | Track Position | Very Easy Code | c-track-position-very-easy-code-by-ankit-g1yc | Please Upvote :)\n\n\nclass Solution {\npublic:\n bool checkDistances(string s, vector<int>& distance) {\n vector<int> a(26,-1);\n for(int i=0; | ankit4601 | NORMAL | 2022-09-04T06:16:32.563065+00:00 | 2022-09-04T06:16:32.563109+00:00 | 221 | false | Please Upvote :)\n\n```\nclass Solution {\npublic:\n bool checkDistances(string s, vector<int>& distance) {\n vector<int> a(26,-1);\n for(int i=0;i<s.length();i++)\n {\n int t=a[s[i]-\'a\'];\n if(t==-1)\n a[s[i]-\'a\']=i;\n else\n {\n ... | 2 | 0 | ['C', 'C++'] | 0 |
check-distances-between-same-letters | ✅✅Faster || Easy To Understand || C++ Code | faster-easy-to-understand-c-code-by-__kr-unob | Using Hashmap\n\n Time Complexity :- O(N * Constant)\n\n Space Complexity :- O(Constant)\n\n\nclass Solution {\npublic:\n bool checkDistances(string str, vec | __KR_SHANU_IITG | NORMAL | 2022-09-04T05:07:47.976302+00:00 | 2022-09-04T05:07:47.976344+00:00 | 251 | false | * ***Using Hashmap***\n\n* ***Time Complexity :- O(N * Constant)***\n\n* ***Space Complexity :- O(Constant)***\n\n```\nclass Solution {\npublic:\n bool checkDistances(string str, vector<int>& distance) {\n \n int n = str.size();\n \n vector<int> dist(26, 0);\n \n for(char ch... | 2 | 0 | ['C', 'C++'] | 0 |
check-distances-between-same-letters | Two C++ Solutions | Linear Complexity | two-c-solutions-linear-complexity-by-tra-zyag | O(n) time, O(n) space, n = s.length\ncpp\nclass Solution {\npublic:\n bool checkDistances(string &s, vector<int> &dist) {\n unordered_map<char, vector | travanj05 | NORMAL | 2022-09-04T04:56:02.892537+00:00 | 2022-09-04T04:56:02.892571+00:00 | 140 | false | 1. O(n) time, O(n) space, n = s.length\n```cpp\nclass Solution {\npublic:\n bool checkDistances(string &s, vector<int> &dist) {\n unordered_map<char, vector<int>> mp;\n for (int i = 0; i < s.size(); i++) {\n mp[s[i]].push_back(i);\n }\n for (auto &[key, val] : mp) {\n ... | 2 | 0 | ['Array', 'C', 'C++'] | 0 |
check-distances-between-same-letters | ✅C++ || ✅Easily Understandable || ✅Commented | c-easily-understandable-commented-by-may-f9y4 | \nclass Solution {\npublic:\n bool checkDistances(string s, vector<int>& distance) \n {\n int n = s.length();\n char tmp;\n \n | mayanksamadhiya12345 | NORMAL | 2022-09-04T04:00:35.653723+00:00 | 2022-09-04T04:06:08.959715+00:00 | 229 | false | ```\nclass Solution {\npublic:\n bool checkDistances(string s, vector<int>& distance) \n {\n int n = s.length();\n char tmp;\n \n for(int i=0;i<n;i++)\n {\n tmp = s[i]; // first occurance of letter\n for(int j=i+1;j<n;j++)\n ... | 2 | 0 | [] | 0 |
check-distances-between-same-letters | Checking Distances Between Same Letters Using Hash Map | checking-distances-between-same-letters-4gro7 | IntuitionThe problem requires checking if the distance between the two occurrences of each letter in the string s matches the corresponding value in the distanc | x7Fg9_K2pLm4nQwR8sT3vYz5bDcE6h | NORMAL | 2025-03-13T12:36:04.848593+00:00 | 2025-03-13T12:36:04.848593+00:00 | 39 | false | # Intuition
The problem requires checking if the distance between the two occurrences of each letter in the string s matches the corresponding value in the distance array. My first thought was to use a hash map to store the indices of each letter in s and then compare the calculated distance with the given distance arr... | 1 | 0 | ['C++'] | 0 |
check-distances-between-same-letters | 100% beats in c++ solution. | 100-beats-in-c-solution-by-jahidulcse15-26fs | IntuitionApproachComplexity
Time complexity:O(N)
Space complexity:O(N)
Code | jahidulcse15 | NORMAL | 2025-01-14T04:01:04.154203+00:00 | 2025-01-14T04:01:04.154203+00:00 | 83 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:O(N)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:O(N)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
... | 1 | 0 | ['C++'] | 0 |
check-distances-between-same-letters | c++ 100% beats solution. | c-100-beats-solution-by-jahidulcse15-f68e | IntuitionApproachComplexity
Time complexity:)(N*N)
Space complexity:O(1)
Code | jahidulcse15 | NORMAL | 2025-01-14T03:57:08.960839+00:00 | 2025-01-14T03:57:08.960839+00:00 | 55 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:)(N*N)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:O(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->... | 1 | 0 | ['C++'] | 0 |
check-distances-between-same-letters | leetcodedaybyday - Beats 100% with C++ and Beats 100% with Python3 | leetcodedaybyday-beats-100-with-c-and-be-haqt | IntuitionThe problem requires checking if the distances between the first and second occurrences of each character in a string match the values provided in an a | tuanlong1106 | NORMAL | 2025-01-09T08:06:04.091536+00:00 | 2025-01-09T08:06:04.091536+00:00 | 75 | false | # Intuition
The problem requires checking if the distances between the first and second occurrences of each character in a string match the values provided in an array. By storing the index of the first occurrence and calculating the distance when encountering the character again, we can efficiently validate the condit... | 1 | 0 | ['Array', 'Hash Table', 'String', 'C++', 'Python3'] | 0 |
check-distances-between-same-letters | Simple solution using hashmap | simple-solution-using-hashmap-by-cs_2201-czzf | Complexity
Time complexity:O(n)
Space complexity:O(n)
Code | CS_2201640100153 | NORMAL | 2024-12-31T17:03:31.713682+00:00 | 2024-12-31T17:03:31.713682+00:00 | 93 | false | # Complexity
- Time complexity:O(n)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:O(n)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```python3 []
class Solution:
def checkDistances(self, s: str, distance: List[int]) -> bool:
d={}
for i in range(len(s)):
... | 1 | 0 | ['Array', 'Hash Table', 'String', 'Python3'] | 0 |
check-distances-between-same-letters | Easy JAVA solution🔥🔥 || Using HashMap || Beginner friendly | easy-java-solution-using-hashmap-beginne-4hm2 | 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 | parthsitoot | NORMAL | 2024-10-17T13:40:24.000584+00:00 | 2024-10-17T13:40:24.000708+00:00 | 66 | 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 | ['Java'] | 1 |
check-distances-between-same-letters | Easy Solution🔥🔥Beat 100% || Detailed Explanation✌️✌️ | easy-solutionbeat-100-detailed-explanati-v2bg | Intuition\nWe simply need to keep a track of the distance between the two occurrences of each character and then check if the string is a well-spaced string.\n\ | anshika_coder467 | NORMAL | 2024-08-03T13:34:59.648709+00:00 | 2024-08-03T13:34:59.648758+00:00 | 160 | false | # Intuition\nWe simply need to keep a track of the distance between the two occurrences of each character and then check if the string is a **well-spaced string**.\n\n# Approach\nHere, an unordered map is used to store the distance between the two occurrences of each character.\n\n- ***First For loop***\nWe store the i... | 1 | 0 | ['C++'] | 1 |
check-distances-between-same-letters | Beats 100% users with C++ | Using Unordered Map in O(n) time. | beats-100-users-with-c-using-unordered-m-l3q5 | Intuition\n Describe your first thoughts on how to solve this problem. \n> The problem requires us to verify if the distances between the repeated characters in | ilokeshmewari | NORMAL | 2024-07-22T08:43:37.269235+00:00 | 2024-07-22T08:43:37.269266+00:00 | 1 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n> The problem requires us to verify if the distances between the repeated characters in a string match the values specified in a given array. Each letter in the alphabet appears exactly twice in the string, and we need to ensure that the ... | 1 | 0 | ['C++'] | 0 |
check-distances-between-same-letters | EASY HASHMAP | easy-hashmap-by-801121-rkk8 | Intuition\nWe need two hashmaps for this problem - one to keep track of the distances corresponding with the alphabet, and the other to find the distances betwe | 801121 | NORMAL | 2024-05-24T12:58:05.621931+00:00 | 2024-07-08T11:29:21.838615+00:00 | 102 | false | # Intuition\nWe need two hashmaps for this problem - one to keep track of the distances corresponding with the alphabet, and the other to find the distances between same letters. \n\n# Approach\nWe will fill the distances hashmap by simply setting the corresponding alphabet letter to the element in distances. \n\nI wil... | 1 | 0 | ['Python3'] | 0 |
check-distances-between-same-letters | use reduce to resolve this problem - 57ms - beats 100% | use-reduce-to-resolve-this-problem-57ms-0ex1c | Code\n\nfunction checkDistances(s: string, distance: number[]): boolean {\n let letter: number;\n const a = \'a\'.charCodeAt(0);\n return s.split(\'\').reduc | soemxui195 | NORMAL | 2024-05-03T13:06:23.754734+00:00 | 2024-05-03T13:06:23.754768+00:00 | 8 | false | # Code\n```\nfunction checkDistances(s: string, distance: number[]): boolean {\n let letter: number;\n const a = \'a\'.charCodeAt(0);\n return s.split(\'\').reduce((isDistance, char, idx) => {\n letter = s[idx].charCodeAt(0) - a;\n if(distance[letter] >= 0) {\n distance[letter] = - distance[letter] - id... | 1 | 0 | ['TypeScript'] | 0 |
check-distances-between-same-letters | Beat 100% CPP solution | beat-100-cpp-solution-by-adityashahi206-774k | Intuition\n Describe your first thoughts on how to solve this problem. \nused Hashmap \n\n# Approach\n Describe your approach to solving the problem. \n 1. c | adityashahi206 | NORMAL | 2024-02-18T05:47:49.153884+00:00 | 2024-02-18T05:47:49.153906+00:00 | 338 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nused Hashmap \n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n 1. create one map which will store first appearance of character\'s index\n 2. if char already exist in map then we will calculate distance betwe... | 1 | 0 | ['Hash Table', 'C++'] | 1 |
check-distances-between-same-letters | Java || Easy To Understand || With Explaination | java-easy-to-understand-with-explainatio-3k06 | Explanation:\n Describe your first thoughts on how to solve this problem. \n\n\n1. Two arrays, arr1 and arr2, are initialized to store the last and second last | akash_kce | NORMAL | 2024-02-01T04:54:02.836036+00:00 | 2024-02-01T04:54:02.836068+00:00 | 220 | false | # Explanation:\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n\n1. Two arrays, `arr1` and `arr2`, are initialized to store the last and second last occurrence indices of each character. These arrays are used to keep track of the positions of characters in the string.\n\n2. The input string `s` ... | 1 | 0 | ['Array', 'String', 'Java'] | 1 |
check-distances-between-same-letters | Easiest Approach - Java (100% Beats) | easiest-approach-java-100-beats-by-talha-b9pp | Code\n\nclass Solution{\n public boolean checkDistances(String s, int[] distance){\n int[] ar1 = new int[26];\n Arrays.fill(ar1, -1);\n | talhah20343 | NORMAL | 2023-08-03T09:33:44.376858+00:00 | 2023-08-03T09:33:44.376888+00:00 | 784 | false | # Code\n```\nclass Solution{\n public boolean checkDistances(String s, int[] distance){\n int[] ar1 = new int[26];\n Arrays.fill(ar1, -1);\n int[] ar2 = new int[26];\n Arrays.fill(ar2, -1);\n for(int i=0; i<s.length(); i++){\n if(ar1[s.charAt(i)-\'a\']!=-1) ar2[s.charAt(... | 1 | 0 | ['Java'] | 0 |
check-distances-between-same-letters | Simple Dictionary C# Solution and Self Explanatory | simple-dictionary-c-solution-and-self-ex-yyfo | \n# Code\n\npublic class Solution {\n public bool CheckDistances(string s, int[] distance) {\n Dictionary<char, int> dc = new Dictionary<char, int>(); | hbti_ankit1994 | NORMAL | 2023-07-29T20:33:25.997717+00:00 | 2023-07-29T20:33:25.997746+00:00 | 52 | false | \n# Code\n```\npublic class Solution {\n public bool CheckDistances(string s, int[] distance) {\n Dictionary<char, int> dc = new Dictionary<char, int>();\n for(int i = 0 ; i < s.Length ; i++)\n {\n if(!dc.ContainsKey(s[i]))\n dc.Add(s[i], i);\n else\n ... | 1 | 0 | ['C#'] | 1 |
check-distances-between-same-letters | ✔✔✔💯% beats in runtime. Easy solution using loops. | beats-in-runtime-easy-solution-using-loo-kzda | 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 | hikmatulloanvarbekov001 | NORMAL | 2023-07-20T15:20:01.083420+00:00 | 2023-07-20T15:20:01.083442+00:00 | 2 | 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 | ['Java'] | 0 |
check-distances-between-same-letters | Simple Solution | simple-solution-by-gauravbisht2709-p0gw | 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 | gauravbisht2709 | NORMAL | 2023-04-22T18:59:35.977553+00:00 | 2023-04-22T18:59:35.977598+00:00 | 698 | 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 | ['Math', 'String', 'Python3'] | 0 |
check-distances-between-same-letters | Check Distances Between Same Letters Solution in C++ | check-distances-between-same-letters-sol-byk5 | 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 | The_Kunal_Singh | NORMAL | 2023-03-22T07:59:54.335527+00:00 | 2023-03-22T07:59:54.335559+00:00 | 30 | 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 | ['C++'] | 0 |
check-distances-between-same-letters | EASY | WITHOUT HASHMAP | 5 Lines of Code | O(1) | C++ | easy-without-hashmap-5-lines-of-code-o1-kdbwo | 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 | shivansh_07 | NORMAL | 2023-02-25T09:02:26.733735+00:00 | 2023-02-25T09:02:26.733773+00:00 | 11 | 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 | ['C++'] | 0 |
check-distances-between-same-letters | HashMap full Approach Explained || Java | hashmap-full-approach-explained-java-by-48syy | Check Distances Between Same Letters\n# Approach:*\n1.) We iterate over the String and create a hashmap\n2.) While iterating if the character is not in hashmap, | pushprajdubey | NORMAL | 2023-01-25T18:11:37.164533+00:00 | 2023-01-25T18:11:37.164583+00:00 | 34 | false | # **Check Distances Between Same Letters\n# ***Approach:*****\n1.) We iterate over the String and create a hashmap\n2.) While iterating if the character is not in hashmap, we put it in hashmap\n3.) If character is in hashmap we compute the number of letter between the two occurences by cuurIndex-ma.get(char)-1 and chec... | 1 | 0 | ['Java'] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.