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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
build-a-matrix-with-conditions | Java Topological Sort - 14ms - 50.7MB | java-topological-sort-14ms-507mb-by-chen-dgqw | As the best approach in 210. Course Schedule II, we can replace HashMap with ArrayList[].\n\nclass Solution {\n public int[][] buildMatrix(int k, int[][] row | chenlize96 | NORMAL | 2022-08-28T04:31:56.528196+00:00 | 2022-08-28T05:43:22.509666+00:00 | 66 | false | As the best approach in 210. Course Schedule II, we can replace HashMap with ArrayList[].\n```\nclass Solution {\n public int[][] buildMatrix(int k, int[][] rowConditions, int[][] colConditions) {\n Map<Integer, List<Integer>> mapR = new HashMap<>();\n Map<Integer, List<Integer>> mapC = new HashMap<>()... | 2 | 0 | ['Topological Sort'] | 0 |
build-a-matrix-with-conditions | C# | c-by-adchoudhary-d401 | Code | adchoudhary | NORMAL | 2025-03-04T05:08:28.244231+00:00 | 2025-03-04T05:08:28.244231+00:00 | 4 | false | # Code
```csharp []
public class Solution {
public int[][] BuildMatrix(int k, int[][] rowConditions, int[][] colConditions)
{
// Store the topologically sorted sequences.
List<int> orderRows = TopoSort(rowConditions, k);
List<int> orderColumns = TopoSort(colConditions, k);
// If no topological... | 1 | 0 | ['C#'] | 0 |
build-a-matrix-with-conditions | C++ code using topological sort (using Kahn's algorithm) | c-code-using-topological-sort-using-kahn-cifs | IntuitionYou can think of each conditions in rowconditions and colconditions as a edge between two vertices.Make a topological sort the all the elements based o | ankurkarn | NORMAL | 2025-02-21T18:11:53.206265+00:00 | 2025-02-21T18:16:14.392472+00:00 | 15 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
You can think of each conditions in rowconditions and colconditions as a edge between two vertices.
Make a topological sort the all the elements based on the rowconditions and colconditions. According to it, find the position of each elemen... | 1 | 0 | ['C++'] | 0 |
build-a-matrix-with-conditions | C++ || Graph || Topological Sort || AVS | c-graph-topological-sort-avs-by-vishal14-ym8e | null | Vishal1431 | NORMAL | 2025-01-03T15:04:25.144896+00:00 | 2025-01-03T15:04:25.144896+00:00 | 17 | false |
```cpp []
class Solution {
public:
vector<vector<int>> buildMatrix(int k, vector<vector<int>>& rowConditions,vector<vector<int>>& colConditions) {
// Store the topologically sorted sequences.
vector<int> orderRows = topoSort(rowConditions, k);
vector<int> orderColumns = topoSort(colConditio... | 1 | 0 | ['Graph', 'Topological Sort', 'C++'] | 0 |
build-a-matrix-with-conditions | Topological sort | topological-sort-by-georgynet-4934 | Complexity\n- Time complexity: O(K^2)\n\n- Space complexity: O(K)\n\n# Code\n\nclass Solution\n{\n /**\n * @param int[][] $rowConditions\n * @param i | georgynet | NORMAL | 2024-07-22T15:50:39.352271+00:00 | 2024-07-22T15:50:39.352307+00:00 | 4 | false | # Complexity\n- Time complexity: $$O(K^2)$$\n\n- Space complexity: $$O(K)$$\n\n# Code\n```\nclass Solution\n{\n /**\n * @param int[][] $rowConditions\n * @param int[][] $colConditions\n * @return int[][]\n */\n public function buildMatrix(int $k, array $rowConditions, array $colConditions): array\... | 1 | 0 | ['PHP'] | 0 |
build-a-matrix-with-conditions | C++ || Topological Sorting || Khan's Algorithm || Cycle Detection | c-topological-sorting-khans-algorithm-cy-niuo | Code\n\nclass Solution {\npublic:\n bool check_cycle(vector<vector<int>> &arr, int n,vector<vector<int>> &g,vector<int> &ans){\n g.resize(n+1);\n | Paras_Punjabi | NORMAL | 2024-07-22T14:38:16.372149+00:00 | 2024-07-22T14:38:16.372180+00:00 | 9 | false | # Code\n```\nclass Solution {\npublic:\n bool check_cycle(vector<vector<int>> &arr, int n,vector<vector<int>> &g,vector<int> &ans){\n g.resize(n+1);\n vector<int> in(n+1,0);\n for(auto item : arr){\n in[item[1]]++;\n g[item[0]].push_back(item[1]);\n }\n queue<... | 1 | 0 | ['Topological Sort', 'Queue', 'Ordered Map', 'C++'] | 1 |
build-a-matrix-with-conditions | Simple toposort question | simple-toposort-question-by-techtinkerer-vpnq | \n\n# Complexity\n- Time complexity:O(n^2)// n^2 can be the maximum number of edges\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(n)\n Add | TechTinkerer | NORMAL | 2024-07-22T11:52:35.163894+00:00 | 2024-07-22T11:52:35.163914+00:00 | 4 | false | \n\n# Complexity\n- Time complexity:O(n^2)// n^2 can be the maximum number of edges\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 {\npublic:\n vector<int> solve(vector<vector<int>> adj){\n int... | 0 | 0 | ['Array', 'Graph', 'Topological Sort', 'Matrix', 'C++'] | 0 |
build-a-matrix-with-conditions | java solution using Topological sort | Graph ☑☑☑ | java-solution-using-topological-sort-gra-1bk3 | \n// use for calculation index\nclass Node{\n int i,j;\n public Node(int i,int j){\n this.i=i;\n this.j=j;\n }\n}\n\nclass Solution {\n | I_am_SOURAV | NORMAL | 2024-07-22T06:56:00.870864+00:00 | 2024-07-22T06:56:00.870908+00:00 | 9 | false | ```\n// use for calculation index\nclass Node{\n int i,j;\n public Node(int i,int j){\n this.i=i;\n this.j=j;\n }\n}\n\nclass Solution {\n \n // detect cycle for directed graph\n public boolean checkCycle(int u,Map<Integer,List<Integer>> adj,boolean []visited,boolean []curStack){\n ... | 1 | 0 | ['Array', 'Graph', 'Topological Sort', 'Matrix', 'Java'] | 0 |
build-a-matrix-with-conditions | Kotlin. Beats 100% (476 ms). IntArrays to sort row and col positions. | kotlin-beats-100-476-ms-intarrays-to-sor-9jkc | \n\n# Code\n\nclass Solution {\n fun buildMatrix(k: Int, rowConditions: Array<IntArray>, colConditions: Array<IntArray>): Array<IntArray> {\n val rows | mobdev778 | NORMAL | 2024-07-22T06:49:35.264728+00:00 | 2024-07-22T06:49:35.264753+00:00 | 6 | false | \n\n# Code\n```\nclass Solution {\n fun buildMatrix(k: Int, rowConditions: Array<IntArray>, colConditions: Array<IntArray>): Array<IntArray> {\n val rows = IntArray(k + 1)\n for (i in 0 unt... | 1 | 0 | ['Kotlin'] | 0 |
build-a-matrix-with-conditions | Very Easy C++ Solution || TOPOSORT | very-easy-c-solution-toposort-by-harshit-nvbd | \n\n# Code\n\nclass Solution {\n vector<int> ts(int V, vector<vector<int>> &adj) {\n vector<int> indegree(V + 1, 0);\n vector<int> ans;\n | harshitgupta_2643 | NORMAL | 2024-07-22T06:09:51.351181+00:00 | 2024-07-22T06:09:51.351226+00:00 | 6 | false | \n\n# Code\n```\nclass Solution {\n vector<int> ts(int V, vector<vector<int>> &adj) {\n vector<int> indegree(V + 1, 0);\n vector<int> ans;\n queue<int> q;\n\n for (int i = 1; i <= V; ++i) {\n for (auto it : adj[i]) {\n indegree[it]++;\n }\n }\n\... | 1 | 0 | ['C++'] | 0 |
build-a-matrix-with-conditions | DarkNerd || TopoLogical Sort | darknerd-topological-sort-by-darknerd-hc53 | 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 | darknerd | NORMAL | 2024-07-22T06:07:20.486162+00:00 | 2024-07-22T06:07:20.486189+00:00 | 5 | 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 |
build-a-matrix-with-conditions | Topological sorting | topological-sorting-by-houssemdev25-2koy | Code\n\nclass Solution {\n public int[][] buildMatrix(int k, int[][] rowConditions, int[][] colConditions) {\n List<Integer> sortedByRow = topological | houssemdev25 | NORMAL | 2024-07-21T23:09:05.032661+00:00 | 2024-07-21T23:09:05.032687+00:00 | 8 | false | # Code\n```\nclass Solution {\n public int[][] buildMatrix(int k, int[][] rowConditions, int[][] colConditions) {\n List<Integer> sortedByRow = topologicalSort(rowConditions, k);\n List<Integer> sortedByCol = topologicalSort(colConditions, k);\n\n if (sortedByRow.isEmpty() || sortedByCol.isEmpty... | 1 | 0 | ['Java'] | 0 |
build-a-matrix-with-conditions | Topological Sort, Easy C++ Solution. | topological-sort-easy-c-solution-by-es22-270y | Intuition\n Describe your first thoughts on how to solve this problem. \nSince the problem is related to which row or column appears before the other.. we need | es22btech11008 | NORMAL | 2024-07-21T21:10:40.422776+00:00 | 2024-07-21T21:10:40.422807+00:00 | 9 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSince the problem is related to which row or column appears before the other.. ***we need to get the order of which element comes before which element***. Only **topological sort** gives such order. So first get the order of the rows and ... | 1 | 0 | ['Topological Sort', 'C++'] | 0 |
build-a-matrix-with-conditions | Well-Structured Graph Solution with Topological Sorting | well-structured-graph-solution-with-topo-4w4z | Intuition\nWe need to build a matrix that satisfies two conditions:\n\n1. Numbers should follow specific row orders.\n2. Numbers should follow specific column o | alyonazhabina | NORMAL | 2024-07-21T21:10:13.169956+00:00 | 2024-07-21T21:10:13.169988+00:00 | 2 | false | # Intuition\nWe need to build a matrix that satisfies two conditions:\n\n1. Numbers should follow specific row orders.\n2. Numbers should follow specific column orders.\n\nTo do this, we first convert these conditions into graphs and then perform topological sorting to find the order of numbers. Finally, we use this or... | 1 | 0 | ['Graph', 'Topological Sort', 'JavaScript'] | 0 |
build-a-matrix-with-conditions | Solution in C | solution-in-c-by-yshkcr-vlpy | this was difficult lol\n\n# Intuition\nit\'s slightly similar to yesterday\'s problem but i still had to bang my head around to wrap all that and actually under | yshkcr | NORMAL | 2024-07-21T18:46:59.309468+00:00 | 2024-07-21T18:46:59.309485+00:00 | 4 | false | this was **difficult** lol\n\n# Intuition\nit\'s slightly similar to yesterday\'s problem but i still had to bang my head around to wrap all that and actually understand the problem. even though i could see think and come up with a solution on paper i knew this was going to be really difficult to code especially in C.\... | 1 | 0 | ['C'] | 0 |
build-a-matrix-with-conditions | Easy to understand!!! | easy-to-understand-by-nehasinghal032415-gb0k | 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 | NehaSinghal032415 | NORMAL | 2024-07-21T18:20:53.442413+00:00 | 2024-07-21T18:20:53.442439+00:00 | 26 | 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 |
build-a-matrix-with-conditions | Easy - Topological sort!! | easy-topological-sort-by-ishaankulkarni1-8kg4 | When we here something should come before something then ---->\nTopo Sort --> Intuition\n# Complexity\n- Time complexity:\nBFS - O(2(k+E)) --> E --> no of edges | ishaankulkarni11 | NORMAL | 2024-07-21T18:20:15.488639+00:00 | 2024-07-21T18:20:15.488669+00:00 | 9 | false | When we here something should come before something then ---->\nTopo Sort --> Intuition\n# Complexity\n- Time complexity:\nBFS - O(2(k+E)) --> E --> no of edges --> 2 time topo sort\nO(2(k+E)) + O(k^2)\n\n- Space complexity:\nIn topo sort --> O(k)\n\n//k is like number of nodes\n\n# Code\n```\nclass Solution {\npublic:... | 1 | 0 | ['C++'] | 1 |
build-a-matrix-with-conditions | 2392. SIMPLE STEP BY STEP SOLUTION | 2392-simple-step-by-step-solution-by-int-zrp3 | Intuition\nThe problem involves constructing a matrix with specific conditions on the rows and columns. The key idea is to use topological sorting to determine | intbliss | NORMAL | 2024-07-21T17:54:08.907757+00:00 | 2024-07-21T17:54:08.907791+00:00 | 11 | false | # Intuition\nThe problem involves constructing a matrix with specific conditions on the rows and columns. The key idea is to use topological sorting to determine the order of elements based on the given conditions. If the conditions form a valid topological order, we can place the elements accordingly; otherwise, it\'s... | 1 | 0 | ['Java'] | 0 |
build-a-matrix-with-conditions | Java BFS solution | java-bfs-solution-by-zerrax-vegt | Explanation\nBoth left to right and above to below form directed graphs. We apply topological sort to both these graphs. If we detect a cycle in either directed | zerraX | NORMAL | 2024-07-21T16:30:09.255597+00:00 | 2024-07-21T16:58:15.012622+00:00 | 29 | false | # Explanation\nBoth left to right and above to below form directed graphs. We apply topological sort to both these graphs. If we detect a cycle in either directed graph, we return an empty matrix. We use a map to map a number to its to indicices provided from both\'s topological sort. We fill the matrix at these indice... | 1 | 0 | ['Java'] | 0 |
build-a-matrix-with-conditions | Build a Matrix With Conditions | build-a-matrix-with-conditions-by-sudhar-6690 | Intuition\n Describe your first thoughts on how to solve this problem. \nTo construct a k x k matrix that satisfies the given row and column conditions, we need | sudharshm2005 | NORMAL | 2024-07-21T15:15:17.117296+00:00 | 2024-07-21T15:15:17.117375+00:00 | 8 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTo construct a k x k matrix that satisfies the given row and column conditions, we need to determine a valid order for placing numbers in rows and columns. This can be achieved by treating the conditions as a dependency graph and ensuring... | 1 | 0 | ['Array', 'Graph', 'Topological Sort', 'Matrix', 'Python3'] | 0 |
build-a-matrix-with-conditions | Most efficient solution using Python | most-efficient-solution-using-python-by-ip3d0 | \n\n# Code\n\nclass Solution(object):\n def buildMatrix(self, k, rowConditions, colConditions):\n rowGraph = defaultdict(list)\n for u, v in ro | vigneshvaran0101 | NORMAL | 2024-07-21T15:04:07.151227+00:00 | 2024-07-21T15:04:07.151256+00:00 | 7 | false | \n\n# Code\n```\nclass Solution(object):\n def buildMatrix(self, k, rowConditions, colConditions):\n rowGraph = defaultdict(list)\n for u, v in rowConditions:\n rowGraph[u].append(v)\n \n colGraph = defaultdict(list)\n for u, v in colConditions:\n colGraph... | 1 | 0 | ['Python3'] | 0 |
build-a-matrix-with-conditions | JAVA easy using Kahn's algorithms | java-easy-using-kahns-algorithms-by-dhar-w538 | ```\nimport java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Queue | dharanip1207 | NORMAL | 2024-07-21T14:50:58.064846+00:00 | 2024-07-21T14:50:58.064870+00:00 | 9 | false | ```\nimport java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Queue;\n\npublic class Solution {\n\n public int[][] buildMatrix(int k, int[][] rowConditions, int[][] colConditions) {\n List<Integer> rowOrder = kahn(row... | 1 | 0 | [] | 0 |
build-a-matrix-with-conditions | Topological Sort | DFS | Python | topological-sort-dfs-python-by-pragya_23-igqc | Complexity\n- Time complexity: O(max(k^2,k+n,k+m)) where n=len(rowConditions) ,m = len(colConditions)\n\n- Space complexity: O(max(k^2,k+n,k+m))\n\n# Code\n\ncl | pragya_2305 | NORMAL | 2024-07-21T14:40:34.407749+00:00 | 2024-07-21T14:40:34.407782+00:00 | 51 | false | # Complexity\n- Time complexity: O(max(k^2,k+n,k+m)) where n=len(rowConditions) ,m = len(colConditions)\n\n- Space complexity: O(max(k^2,k+n,k+m))\n\n# Code\n```\nclass Solution:\n def buildMatrix(self, k: int, rowConditions: List[List[int]], colConditions: List[List[int]]) -> List[List[int]]:\n rowGraph,colG... | 1 | 0 | ['Array', 'Graph', 'Topological Sort', 'Matrix', 'Python', 'Python3'] | 0 |
build-a-matrix-with-conditions | ✅ 🎯 📌 Simple Solution || Beats 83.9% in Time || Topological Sort + Cycle Check ✅ 🎯 📌 | simple-solution-beats-839-in-time-topolo-alru | Approach\n Describe your approach to solving the problem. \nWe first apply topological sort algorithm on rowConditions and colConditions while simultaneously ch | vvnpais | NORMAL | 2024-07-21T14:39:29.719707+00:00 | 2024-07-21T14:41:03.386956+00:00 | 27 | false | # Approach\n<!-- Describe your approach to solving the problem. -->\nWe first apply topological sort algorithm on rowConditions and colConditions while simultaneously checking for cycles in these arrays.\nIf cycle exists, we cannot fulfill the conditions that make up the cycle \nand hence we return $$[\\ \\ ]$$.\nHowev... | 1 | 0 | ['Array', 'Graph', 'Topological Sort', 'Matrix', 'Python3'] | 0 |
build-a-matrix-with-conditions | Hassle Free Method and Easy to Understand | hassle-free-method-and-easy-to-understan-7jic | 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 | fourthofjuly | NORMAL | 2024-07-21T14:32:58.062762+00:00 | 2024-07-21T14:32:58.062793+00:00 | 20 | 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(k*^2 + n)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g... | 1 | 0 | ['Graph', 'Topological Sort', 'Matrix', 'C++'] | 0 |
build-a-matrix-with-conditions | Topological Sort Approach to Build Matrix from Row and Column Conditions || 💯💯💯 | topological-sort-approach-to-build-matri-itr1 | Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem requires creating a matrix based on row and column conditions, which repres | kamalcbe86 | NORMAL | 2024-07-21T14:17:48.919955+00:00 | 2024-07-21T14:17:48.919996+00:00 | 31 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem requires creating a matrix based on row and column conditions, which represent dependencies. Topological sorting is well-suited for this kind of dependency management, as it helps us find a valid ordering for the elements.\n\n... | 1 | 0 | ['Java'] | 0 |
build-a-matrix-with-conditions | ✅NOT SO EASY JAVA SOLUTION😂 | not-so-easy-java-solution-by-swayam28-ecqv | 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 | swayam28 | NORMAL | 2024-07-21T14:13:07.447519+00:00 | 2024-07-21T14:13:07.447548+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)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['Java'] | 0 |
build-a-matrix-with-conditions | Runtime 99ms || C++ || TopoSorting Algorithm || Time complexity O(K+E) & Space complexity O(k^2) | runtime-99ms-c-toposorting-algorithm-tim-qlr2 | Complexity\n- Time complexity:O(K+E)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(k^2) //for final matrix\n Add your space complexity he | sneha029 | NORMAL | 2024-07-21T13:43:32.611585+00:00 | 2024-07-21T13:43:32.611613+00:00 | 18 | false | # Complexity\n- Time complexity:O(K+E)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(k^2) //for final matrix\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n void topoSortUtil(stack<int>& stk, vector<int>& vis, int curr, vector<vect... | 1 | 0 | ['C++'] | 0 |
build-a-matrix-with-conditions | || Easy solution in C++|| | easy-solution-in-c-by-dhanu07-upuf | Intuition\n Describe your first thoughts on how to solve this problem. \nSince we have given the RowCon and ColCon like nodess and we have to sort them. Therefo | Dhanu07 | NORMAL | 2024-07-21T13:16:44.504951+00:00 | 2024-07-21T13:16:44.504983+00:00 | 8 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSince we have given the RowCon and ColCon like nodess and we have to sort them. Therefore the first thing came to mind is Topological Sort.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nIt follows a simple Approach... | 1 | 0 | ['Array', 'Graph', 'Topological Sort', 'Matrix', 'C++'] | 0 |
build-a-matrix-with-conditions | Java Solution | java-solution-by-okiee-zapn | Code\n\nclass Solution {\n public int[][] buildMatrix(int k, int[][] rowConditions, int[][] colConditions) {\n List<Integer>[] rowGraph = new ArrayLis | Okiee | NORMAL | 2024-07-21T12:46:23.116670+00:00 | 2024-07-21T12:46:23.116703+00:00 | 12 | false | # Code\n```\nclass Solution {\n public int[][] buildMatrix(int k, int[][] rowConditions, int[][] colConditions) {\n List<Integer>[] rowGraph = new ArrayList[k + 1]; \n for(int i = 1 ; i < rowGraph.length; i ++) {\n rowGraph[i] = new ArrayList();\n }\n for(int [] rowCondition : ... | 1 | 0 | ['Java'] | 0 |
build-a-matrix-with-conditions | Swift | DFS Topological Sort (+ Kahn) | swift-dfs-topological-sort-kahn-by-pagaf-dbwh | I originally wrote this using DFS Topological Sort (dfsSort()) but I\'m adding Kahn\'s Topological Sort (khansSort()) for comparison, since most solutions use t | pagafan7as | NORMAL | 2024-07-21T12:40:37.910690+00:00 | 2024-07-22T13:41:59.720275+00:00 | 28 | false | I originally wrote this using **DFS Topological Sort** (```dfsSort()```) but I\'m adding **Kahn\'s Topological Sort** (```khansSort()```) for comparison, since most solutions use that algorithm.\n\nAsymptotically, they both run in O(V + E) time and in practice they seem roughly equivalent.\n\nI thought that one may be ... | 1 | 0 | ['Swift'] | 0 |
build-a-matrix-with-conditions | Topological sort using DFS & Kahn's algorithm + optimizations. | topological-sort-using-dfs-kahns-algorit-dri6 | All we need is to sort rows and cols dependencies in topological order. If we look at provided example Input: k = 3, rowConditions = [[1,2],[3,2]], colCondition | AlexPG | NORMAL | 2024-07-21T11:44:48.906224+00:00 | 2024-07-21T14:52:59.178212+00:00 | 17 | false | All we need is to sort rows and cols dependencies in topological order. If we look at provided example Input: k = 3, rowConditions = [[1,2],[3,2]], colConditions = [[2,1],[3,2]] we can see, that if we construct graphs for rows&cols conditions and then sort vertices of those graphs in topological order we would have nex... | 1 | 0 | ['C++'] | 0 |
check-balanced-string | Python3 || 2 lines, map and separate || T/S: 99% / 96% | python3-2-lines-map-and-separate-ts-99-9-hgj8 | Here\'s the plan:\n1. We map the characters in num to integers.\n\n1. We sum the even-indexed elements of num and we sum the even-indexed elements of num, and t | Spaulding_ | NORMAL | 2024-11-03T05:29:13.730688+00:00 | 2024-11-11T21:43:22.919826+00:00 | 1,122 | false | Here\'s the plan:\n1. We map the characters in `num` to integers.\n\n1. We sum the even-indexed elements of `num` and we sum the even-indexed elements of `num`, and then we return whether they are equal. \n ___\n\n```python3 []\nclass Solution:\n def isBalanced(self, num: str) -> bool:\n\n num = list(map(int,... | 17 | 0 | ['C++', 'Java', 'Python3'] | 1 |
check-balanced-string | [Java/C++/Python] Calculate the Diff | javacpython-calculate-the-diff-by-lee215-t4fw | Time O(n)\nSpace O(1)\n\nJava [Java]\n public boolean isBalanced(String num) {\n int diff = 0, sign = 1, n = num.length();\n for (int i = 0; i | lee215 | NORMAL | 2024-11-03T04:36:27.988658+00:00 | 2024-11-03T04:36:55.229820+00:00 | 1,367 | false | Time `O(n)`\nSpace `O(1)`\n\n```Java [Java]\n public boolean isBalanced(String num) {\n int diff = 0, sign = 1, n = num.length();\n for (int i = 0; i < n; ++i) {\n diff += sign * (num.charAt(i) - \'0\');\n sign = -sign;\n }\n return diff == 0;\n }\n```\n\n```C++ [... | 14 | 0 | ['C', 'Python', 'Java'] | 2 |
check-balanced-string | Easy & Clear Solution (Java, c++, Python3) | easy-clear-solution-java-c-python3-by-mo-02qb | \n\n### C++ \ncpp\nclass Solution {\npublic:\n bool isBalanced(string num) {\n int evenSum = 0, oddSum = 0;\n for (int i = 0; i < num.length(); | moazmar | NORMAL | 2024-11-03T04:05:59.032230+00:00 | 2024-11-03T04:05:59.032257+00:00 | 1,383 | false | \n\n### C++ \n```cpp\nclass Solution {\npublic:\n bool isBalanced(string num) {\n int evenSum = 0, oddSum = 0;\n for (int i = 0; i < num.length(); i++) {\n if (i % 2 == 0) {\n evenSum += num[i] - \'0\'; // Convert char to int\n } else {\n oddSum += nu... | 8 | 0 | ['Python', 'C++', 'Java', 'Python3'] | 1 |
check-balanced-string | Overcomplicated Python Solution🐍(watch to learn smth new) | overcomplicated-python-solutionwatch-to-o1woo | IntuitionIn a balanced string sum of all odd-places and even-places numbers is the same so their difference is 0.In writing the solution this article helped me: | karasik8765 | NORMAL | 2025-02-14T12:32:39.952110+00:00 | 2025-02-14T12:32:39.952110+00:00 | 159 | false | # Intuition
In a balanced string sum of all odd-places and even-places numbers is the same so their difference is **0**.
In writing the solution this article helped me: https://stackoverflow.com/questions/59092561/how-to-use-iterator-in-while-loop-statement-in-python
So we just add all numbers on even positions and s... | 5 | 0 | ['Python3'] | 1 |
check-balanced-string | 💢☠💫Easiest👾Faster✅💯 Lesser🧠 🎯 C++✅Python3🐍✅Java✅C✅Python🐍✅C#✅💥🔥💫Explained☠💥🔥 Beats 100 | easiestfaster-lesser-cpython3javacpython-eoqe | Intuition\n\n Describe your first thoughts on how to solve this problem. \n- JavaScript Code --> https://leetcode.com/problems/check-balanced-string/submissions | Edwards310 | NORMAL | 2024-11-03T10:34:28.241535+00:00 | 2024-11-03T10:34:28.241569+00:00 | 223 | false | # Intuition\n\n<!-- Describe your first thoughts on how to solve this problem. -->\n- ***JavaScript Code -->*** https://leetcode.com/problems/check-balanced-string/submissions/1441645507\n- ***C++ ... | 5 | 1 | ['Math', 'String', 'C', 'String Matching', 'Python', 'C++', 'Java', 'Python3', 'JavaScript', 'C#'] | 0 |
check-balanced-string | Easy and simple solution || Beats 100% || String || c++ || Python | easy-and-simple-solution-beats-100-strin-p3eh | C++\ncpp\nclass Solution {\npublic:\n bool isBalanced(string num) {\n int odd = 0;\n int even = 0;\n for (int i = 0; i < num.size(); i++ | BijoySingh7 | NORMAL | 2024-11-03T04:28:39.454838+00:00 | 2024-11-03T04:28:39.454863+00:00 | 292 | false | ### C++\n```cpp\nclass Solution {\npublic:\n bool isBalanced(string num) {\n int odd = 0;\n int even = 0;\n for (int i = 0; i < num.size(); i++) {\n int digit = num[i] - \'0\';\n if (i % 2)\n odd += digit;\n else\n even += digit;\n ... | 5 | 0 | ['String', 'Python', 'C++', 'Python3'] | 2 |
check-balanced-string | C++ 1-liner||0ms beats 100% | c-1-liner0ms-beats-100-by-anwendeng-1mot | Intuition\n Describe your first thoughts on how to solve this problem. \nUse alternating sum; if sum=0 return 1 otherwise 0\n# Approach\n Describe your approach | anwendeng | NORMAL | 2024-11-03T04:19:12.244182+00:00 | 2024-11-03T04:31:02.773902+00:00 | 283 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nUse alternating sum; if sum=0 return 1 otherwise 0\n# Approach\n<!-- Describe your approach to solving the problem. -->\nUse accumulate with lambda function\n```\n[&, i=1](int sum, char x) mutable{\n return sum+=(i*=(-1))*(x-\'0\');\n}... | 5 | 0 | ['C++'] | 1 |
check-balanced-string | For beginners , Beats 100 % of other submissions' runtime. | for-beginners-beats-100-of-other-submiss-5vvd | Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem requires determining if the sum of digits at even indices in a string match | deep94725kumar | NORMAL | 2024-11-03T04:05:33.100015+00:00 | 2024-11-03T04:05:33.100042+00:00 | 771 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem requires determining if the sum of digits at even indices in a string matches the sum of digits at odd indices. The first idea is to iterate through the string, keep track of the sum for both even and odd index positions, and ... | 5 | 0 | ['C++'] | 1 |
check-balanced-string | Python solution | python-solution-by-divyap09-v6cm | Intuition\n Describe your first thoughts on how to solve this problem. \nWe need to calculate the sum of elements at even and odd indices separately and check w | divyap09 | NORMAL | 2024-11-27T09:01:48.637444+00:00 | 2024-11-27T09:01:48.637498+00:00 | 98 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe need to calculate the sum of elements at even and odd indices separately and check whether both sums are equal or not.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nSince we have to traverse through each posit... | 4 | 0 | ['Python3'] | 1 |
check-balanced-string | Easy beats 100% | easy-beats-100-by-mainframekuznetsov-intc | Intuition\n Describe your first thoughts on how to solve this problem. \nBasic Implementation based problem\n# Approach\n Describe your approach to solving the | MainFrameKuznetSov | NORMAL | 2024-11-03T04:36:14.114514+00:00 | 2024-11-03T08:00:46.119521+00:00 | 99 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nBasic Implementation based problem\n# Approach\n<!-- Describe your approach to solving the problem. -->\nJust compute the sums in even and odd positions and check if they are equal or not\n# Complexity\n- Time complexity:- $O(n)$\n<!-- Ad... | 3 | 0 | ['String', 'C++', 'Java', 'Python3'] | 0 |
check-balanced-string | 🌹 EASY SOLUTION [SINGLE VARIABLE] | easy-solution-single-variable-by-ramitga-w8ur | \n\n# \uD83D\uDC93**_PLEASE CONSIDER UPVOTING_**\uD83D\uDC93\n\n \n\n\n\n# \u2B50 Intuition\nThe task is to determine if the string of digits is balanced. A bal | ramitgangwar | NORMAL | 2024-11-03T04:02:19.888587+00:00 | 2024-11-03T04:02:19.888633+00:00 | 55 | false | <div align="center">\n\n# \uD83D\uDC93**_PLEASE CONSIDER UPVOTING_**\uD83D\uDC93\n\n</div>\n\n***\n\n# \u2B50 Intuition\nThe task is to determine if the string of digits is balanced. A balanced string is defined by the condition that the sum of the digits at even indices equals the sum of the digits at odd indices. The... | 3 | 1 | ['String', 'Java'] | 0 |
check-balanced-string | Check if a Number is Balanced Based on Digit Sums | check-if-a-number-is-balanced-based-on-d-qss0 | IntuitionThe problem requires checking whether the sum of digits at even indices is equal to the sum of digits at odd indices in a given string representation o | pramv | NORMAL | 2025-02-15T14:10:52.949952+00:00 | 2025-02-15T14:10:52.949952+00:00 | 131 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The problem requires checking whether the sum of digits at even indices is equal to the sum of digits at odd indices in a given string representation of a number. My first thought is to iterate through the string and maintain two separate s... | 2 | 0 | ['String', 'C++'] | 1 |
check-balanced-string | easy spicy ans | easy-spicy-ans-by-djett0nars-huy7 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | djeTt0NarS | NORMAL | 2025-02-01T09:08:11.978254+00:00 | 2025-02-01T09:08:11.978254+00:00 | 90 | 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 | ['Python3'] | 0 |
check-balanced-string | Beats 100% users in Time Complexity | Understandable python approach | beats-100-users-in-time-complexity-under-2icj | IntuitionApproachComplexity
Time complexity:O(N)
Space complexity:O(N)
Code | atharvmittal9876 | NORMAL | 2024-12-28T13:42:38.521960+00:00 | 2024-12-28T13:42:38.521960+00:00 | 50 | 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)$$ -->
... | 2 | 0 | ['String', 'Python', 'Python3'] | 0 |
check-balanced-string | simple and easy C++ solution | simple-and-easy-c-solution-by-shishirrsi-l3pq | if it\'s help, please up \u2B06 vote! \u2764\uFE0F\n###### Let\'s Connect on Linkedin: www.linkedin.com/in/shishirrsiam\n\n\n\n# Code\ncpp []\nclass Solution {\ | shishirRsiam | NORMAL | 2024-11-07T07:32:55.824888+00:00 | 2024-11-07T07:32:55.824931+00:00 | 112 | false | # if it\'s help, please up \u2B06 vote! \u2764\uFE0F\n###### Let\'s Connect on Linkedin: www.linkedin.com/in/shishirrsiam\n\n\n\n# Code\n```cpp []\nclass Solution {\npublic:\n bool isBalanced(string num) \n {\n map<int, int>mp;\n bool flag = true;\n for(auto ch:num)\n {\n mp... | 2 | 0 | ['String', 'C++'] | 3 |
check-balanced-string | Golang simple solution | golang-simple-solution-by-evanfang-x84r | \n\n# Code\ngolang []\nfunc isBalanced(num string) bool {\n var sum rune\n for i, n := range(num) {\n if i % 2 == 0 {\n sum += (n - \'0\ | evanfang | NORMAL | 2024-11-06T11:38:52.929449+00:00 | 2024-11-06T11:38:52.929492+00:00 | 32 | false | \n\n# Code\n```golang []\nfunc isBalanced(num string) bool {\n var sum rune\n for i, n := range(num) {\n if i % 2 == 0 {\n sum += (n - \'0\')\n } else {\n sum -= (n - \'0\')\n }\n }\n return sum == 0\n}\n``` | 2 | 0 | ['Go'] | 0 |
check-balanced-string | Python3 | python3-by-dereksd2019-0ujp | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nCalculated the length o | dereksd2019 | NORMAL | 2024-11-04T11:10:34.893061+00:00 | 2024-11-04T11:10:34.893097+00:00 | 98 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nCalculated the length of a string. For example, 1234 has length of 4. Got the string of even indices and odd indices. Calculated the digit sum of the string of even ... | 2 | 0 | ['Python3'] | 1 |
check-balanced-string | Linear solution with constant space | linear-solution-with-constant-space-by-g-x259 | Approach\nThe solution is very straightforward, we calculate the sum of digits in even indices and the sum of digits in odd indices. We can optimize things a li | gomezdavid89 | NORMAL | 2024-11-03T17:01:38.536446+00:00 | 2024-11-22T22:36:06.034039+00:00 | 14 | false | # Approach\nThe solution is very straightforward, we calculate the sum of digits in even indices and the sum of digits in odd indices. We can optimize things a little bit by computing a single sum like: $$num[0] - num[1] + num[2] - num[3] + ...$$, where the final sum should be equal to $$0$$.\n\n# Complexity\n- Time co... | 2 | 0 | ['Rust'] | 1 |
check-balanced-string | 💯Very Easy Detailed Solution || 🎯Beats 100% of the users || 🎯 Brute Force | very-easy-detailed-solution-beats-100-of-xrqn | Intuition\n Describe your first thoughts on how to solve this problem. \nWe will take two variable to maitain the count of digits at even and odd indices, and t | chaturvedialok44 | NORMAL | 2024-11-03T08:39:51.331707+00:00 | 2024-11-03T08:39:51.331728+00:00 | 254 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe will take two variable to maitain the count of digits at even and odd indices, and then will check if both equals or not.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Initialize two variables \'evenSum\' and... | 2 | 0 | ['Math', 'Two Pointers', 'String', 'String Matching', 'Java'] | 2 |
check-balanced-string | Java Clean Solution | java-clean-solution-by-shree_govind_jee-21eb | Code\njava []\nclass Solution {\n public boolean isBalanced(String num) {\n long odd = 0, even = 0;\n for (int i = 0; i < num.length(); i++) {\ | Shree_Govind_Jee | NORMAL | 2024-11-03T04:05:07.712833+00:00 | 2024-11-03T04:05:07.712875+00:00 | 104 | false | # Code\n```java []\nclass Solution {\n public boolean isBalanced(String num) {\n long odd = 0, even = 0;\n for (int i = 0; i < num.length(); i++) {\n if (i % 2 == 0) {\n even += num.charAt(i) - \'0\';\n } else {\n odd += num.charAt(i) - \'0\';\n ... | 2 | 0 | ['Math', 'String', 'String Matching', 'Java'] | 0 |
check-balanced-string | ✅ Simple Java Solution | simple-java-solution-by-harsh__005-z5f9 | CODE\nJava []\npublic boolean isBalanced(String num) {\n int s1=0, s2 = 0, n = num.length();\n for(int i=0; i<n; i++) {\n char ch = num.charAt(i);\ | Harsh__005 | NORMAL | 2024-11-03T04:04:12.648160+00:00 | 2024-11-03T04:04:12.648186+00:00 | 199 | false | ## **CODE**\n```Java []\npublic boolean isBalanced(String num) {\n int s1=0, s2 = 0, n = num.length();\n for(int i=0; i<n; i++) {\n char ch = num.charAt(i);\n if(i%2 == 0) {\n s2 += (ch-\'0\');\n } else {\n s1 += (ch-\'0\');\n }\n }\n return s1==s2;\n}\n``` | 2 | 0 | ['Java'] | 1 |
check-balanced-string | Stop checking solution for wayyyyy to easy problem kid | stop-checking-solution-for-wayyyyy-to-ea-gljj | IntuitionYes i know what you thinking cmon dude just implement it already stop checking solutions for wayyyy to easy problem you ain't gonna learn anythingBoldA | _Aryan_Gupta | NORMAL | 2025-04-09T07:11:39.107689+00:00 | 2025-04-09T07:11:39.107689+00:00 | 10 | false | # Intuition
# Yes i know what you thinking cmon dude just implement it already stop checking solutions for wayyyy to easy problem you ain't gonna learn anything**Bold**
# Approach
Just do what question says you got it
# Complexity
- Time complexity:
O(N)
- Space complexity:
O(1)
# Code
```cpp []
class Solution {
pu... | 1 | 0 | ['C++'] | 0 |
check-balanced-string | Easy Solution Python3 | easy-solution-python3-by-adhi_m_s-ytk6 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | Adhi_M_S | NORMAL | 2025-03-20T10:22:00.622506+00:00 | 2025-03-20T10:22:00.622506+00:00 | 51 | 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 |
check-balanced-string | getNumericValue way | getnumericvalue-way-by-sairangineeni-jiyq | IntuitionConvert string to int by using Character.getNumericValue(num.charAt(i));after that if index is even then add to even or otherwise to oddcheck if they m | Sairangineeni | NORMAL | 2025-03-10T06:55:39.834026+00:00 | 2025-03-10T06:55:39.834026+00:00 | 46 | false | # Intuition
Convert string to int by using Character.getNumericValue(num.charAt(i));
after that if index is even then add to even or otherwise to odd
check if they match, if not return false.
# Code
```java []
class Solution {
public static boolean isBalanced(String num) {
int even = 0;
int odd = 0;
fo... | 1 | 0 | ['Java'] | 0 |
check-balanced-string | best solution | best-solution-by-haneen_ep-te3m | IntuitionThis solution determines if a number represented as a string is "balanced" by comparing the sum of digits at even positions with the sum of digits at o | haneen_ep | NORMAL | 2025-03-06T17:38:18.703642+00:00 | 2025-03-06T17:38:18.703642+00:00 | 68 | false | # Intuition
This solution determines if a number represented as a string is "balanced" by comparing the sum of digits at even positions with the sum of digits at odd positions. A number is considered balanced if both sums are equal.
# Approach
- Initialize two counters: even for the sum of digits at even positions an... | 1 | 0 | ['JavaScript'] | 0 |
check-balanced-string | Simple Python Solution --- UNDERSTANDABLE --- BEGINNER FRIENDLY | simple-python-solution-understandable-be-fqpe | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | 22A31A05A9 | NORMAL | 2025-02-16T19:49:51.686756+00:00 | 2025-02-16T19:49:51.686756+00:00 | 21 | 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 | ['Python'] | 0 |
check-balanced-string | Easiest Solution in Java | easiest-solution-in-java-by-sathurnithy-1lpu | Code | Sathurnithy | NORMAL | 2025-02-04T13:32:04.318650+00:00 | 2025-02-04T13:32:04.318650+00:00 | 100 | false | # Code
```java []
class Solution {
public boolean isBalanced(String num) {
int oddSum = 0, evenSum = 0, len = num.length();
for (int i = 0; i < len; i++) {
if (i % 2 == 0)
evenSum += (num.charAt(i) - '0');
else
oddSum += (num.charAt(i) - '0');
... | 1 | 0 | ['String', 'Java'] | 0 |
check-balanced-string | Easiest Solution in C | easiest-solution-in-c-by-sathurnithy-5zx4 | Code | Sathurnithy | NORMAL | 2025-02-04T13:29:51.587698+00:00 | 2025-02-04T13:29:51.587698+00:00 | 40 | false | # Code
```c []
bool isBalanced(char* num) {
int oddSum = 0, evenSum = 0, len = strlen(num);
for (int i = 0; i < len; i++) {
if (i % 2 == 0)
evenSum += (num[i] - '0');
else
oddSum += (num[i] - '0');
}
return oddSum == evenSum;
}
``` | 1 | 0 | ['String', 'C'] | 0 |
check-balanced-string | Solution in Java and C | solution-in-java-and-c-by-vickyy234-d4ur | Code | vickyy234 | NORMAL | 2025-02-03T17:45:18.068481+00:00 | 2025-02-03T17:45:18.068481+00:00 | 47 | false | # Code
```c []
bool isBalanced(char* num) {
int odd = 0, even = 0, len = strlen(num);
int i = 0;
while (i < len) {
odd += (num[i] - 48);
i += 2;
}
i = 1;
while (i < len) {
even += (num[i] - 48);
i += 2;
}
return odd == even;
}
```
```Java []
class Solution... | 1 | 0 | ['String', 'C', 'Java'] | 0 |
check-balanced-string | Easy answer in 1 loop | easy-answer-in-1-loop-by-saksham_gupta-tbsx | Complexity
Time complexity: O(n)
Space complexity: O(1)
Code | Saksham_Gupta_ | NORMAL | 2025-01-14T18:36:13.342326+00:00 | 2025-01-14T18:36:13.342326+00:00 | 106 | false |
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity: ***O(n)***
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity: ***O(1)***
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```java []
class Solution {
public boolean isBalanced(String num) ... | 1 | 0 | ['Java'] | 0 |
check-balanced-string | Easy solution: Using one variable for sum instead of two. | easy-solution-using-one-variable-for-sum-hv95 | IntuitionMy initial thought was to create two variables, even_sum and odd_sum, and then loop through the digits to calculate their respective sums.However, I re | ekbullock | NORMAL | 2025-01-13T00:40:58.409314+00:00 | 2025-01-13T00:40:58.409314+00:00 | 20 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
My initial thought was to create two variables, even_sum and odd_sum, and then loop through the digits to calculate their respective sums.
However, I realized there is a simpler way to solve this. Instead of maintaining two separate variab... | 1 | 0 | ['Python3'] | 0 |
check-balanced-string | BEATING 99% IN 1ms EASY JAVA CODE | beating-99-in-1ms-easy-java-code-by-arsh-epqc | ApproachTo solve this problem efficiently, we can break it down into the following steps:
Initialization:
We need to keep track of the sums of digits at even an | arshi_bansal | NORMAL | 2025-01-11T12:37:25.638738+00:00 | 2025-01-11T12:37:25.638738+00:00 | 61 | false | # Approach
<!-- Describe your approach to solving the problem. -->
To solve this problem efficiently, we can break it down into the following steps:
1. Initialization:
We need to keep track of the sums of digits at even and odd indices. We can initialize two variables: s1 (for odd indices) and s2 (for even indices).
W... | 1 | 0 | ['Java'] | 0 |
check-balanced-string | ☑️ Checking if given string is Balanced. ☑️ | checking-if-given-string-is-balanced-by-85sxr | Code | Abdusalom_16 | NORMAL | 2024-12-17T17:06:49.016123+00:00 | 2024-12-17T17:06:49.016123+00:00 | 45 | false | # Code\n```dart []\nclass Solution {\n bool isBalanced(String num) {\n int even = 0;\n int odd = 0;\n for(int i = 0;i < num.length; i++){\n if(i.isEven){\n even+= int.parse(num[i]);\n }else{\n odd+= int.parse(num[i]);\n }\n }\n\n return even == odd;\n }\n}\n``... | 1 | 0 | ['String', 'Dart'] | 0 |
check-balanced-string | easy C solution | Runtime Beats 100.00% | easy-c-solution-runtime-beats-10000-by-j-p6x6 | IntuitionConsider the even digits as positive numbers and the odd digits and negative numbers. After adding all the digits this way, the result should be zero i | JoshDave | NORMAL | 2024-12-16T04:24:04.858122+00:00 | 2024-12-16T04:24:04.858122+00:00 | 58 | false | # Intuition\nConsider the even digits as positive numbers and the odd digits and negative numbers. After adding all the digits this way, the result should be zero if the string is balanced. So add all the numbers from the string and rather than deciding whether to add or subtract, simply take the opposite of the number... | 1 | 0 | ['Math', 'String', 'C'] | 0 |
check-balanced-string | 1 ms, Beats 99% | 1-ms-beats-99-by-sorokus-dev-45d1 | Intuition\nCount the sums of even and odd digints in the string.\n\n# Approach\nIterate over the string.\nExtract a character and convert it into integer value | sorokus-dev | NORMAL | 2024-11-28T07:01:57.724936+00:00 | 2024-11-28T07:01:57.724959+00:00 | 18 | false | # Intuition\nCount the sums of even and odd digints in the string.\n\n# Approach\nIterate over the string.\nExtract a character and convert it into integer value simply subtracting \'0\' character from it. Increment odd/even counter respectively.\nDon\'t forget to check if an iteration variable \'i\' is in scope.\n\n\n... | 1 | 0 | ['Java'] | 0 |
check-balanced-string | Easy js solution | easy-js-solution-by-joelll-nuuu | 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 | Joelll | NORMAL | 2024-11-27T09:40:40.415183+00:00 | 2024-11-27T09:40:40.415223+00:00 | 58 | 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 | ['JavaScript'] | 0 |
check-balanced-string | Easy 📶 solution with each step by step procedure with 🗿 O(n) | easy-solution-with-each-step-by-step-pro-zlom | 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 | shamnad_skr | NORMAL | 2024-11-26T04:20:32.235948+00:00 | 2024-11-26T04:21:03.496449+00:00 | 44 | 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 | ['TypeScript', 'JavaScript'] | 0 |
check-balanced-string | C++ sum | c-sum-by-michelusa-q99p | Sum should be zero\n\ncpp []\nclass Solution {\npublic:\n bool isBalanced(string_view num) {\n int sum = 0;\n int sign = 1;\n for (size_ | michelusa | NORMAL | 2024-11-25T13:37:57.115785+00:00 | 2024-11-25T13:37:57.115823+00:00 | 5 | false | Sum should be zero\n\n```cpp []\nclass Solution {\npublic:\n bool isBalanced(string_view num) {\n int sum = 0;\n int sign = 1;\n for (size_t idx = 0; idx != num.size(); ++idx, sign *= -1) {\n sum += sign * (num[idx] - \'0\');\n }\n\n return !sum;\n }\n};\n``` | 1 | 0 | ['C++'] | 0 |
check-balanced-string | O(N) easy solution in python | on-easy-solution-in-python-by-nikasvante-ckd0 | Time complexity: O(N)\n\n- Space complexity: O(N)\n\n# Code\npython3 []\nclass Solution:\n def isBalanced(self, num: str) -> bool:\n odd,even = 0,0\n | nikasvantes | NORMAL | 2024-11-21T16:23:59.950533+00:00 | 2024-11-21T16:23:59.950560+00:00 | 30 | false | - Time complexity: O(N)\n\n- Space complexity: O(N)\n\n# Code\n```python3 []\nclass Solution:\n def isBalanced(self, num: str) -> bool:\n odd,even = 0,0\n for odd_num in range(1,len(num),2):\n odd += int(num[odd_num])\n for even_num in range(0,len(num),2):\n even += int(num[eve... | 1 | 0 | ['Python3'] | 0 |
check-balanced-string | Easy solution | easy-solution-by-chandranshu31-rkjj | 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 | Chandranshu31 | NORMAL | 2024-11-18T14:51:44.755299+00:00 | 2024-11-18T14:51:44.755370+00:00 | 17 | 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-balanced-string | BEATS 99.5% || MOST OPTIMIZED SOLUTION IN JAVA | beats-995-most-optimized-solution-in-jav-i9bq | \n# Code\njava []\nclass Solution \n{\n public boolean isBalanced(String num) \n {\n int n = num.length();\n int even = 0;\n int odd | dawncindrela | NORMAL | 2024-11-13T15:07:38.763548+00:00 | 2024-11-13T15:07:38.763586+00:00 | 40 | false | \n# Code\n```java []\nclass Solution \n{\n public boolean isBalanced(String num) \n {\n int n = num.length();\n int even = 0;\n int odd = 0;\n for(int i=0;i<n;i++)\n {\n if(i % 2 == 0)\n {\n even += (num.charAt(i)-\'0\');\n }\n ... | 1 | 0 | ['String', 'Java'] | 0 |
check-balanced-string | For beginners C++, Beats 100 % | for-beginners-c-beats-100-by-shashankkk1-xfxp | Intuition\n Describe your first thoughts on how to solve this problem. \nThe goal is to determine if a string of digits is "balanced" based on the sums of its d | shashankkk1212 | NORMAL | 2024-11-10T10:58:03.821492+00:00 | 2024-11-10T10:58:03.821522+00:00 | 9 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe goal is to determine if a string of digits is "balanced" based on the sums of its digits at even and odd indices. To solve this, we can:\n\n- Separate the digits based on whether they\u2019re located at even or odd - indices.\n- Sum u... | 1 | 0 | ['C++'] | 0 |
check-balanced-string | After a long gap of 17 days posting a soln bahut lamba break hua resume krna hope so ho jay :D | after-a-long-gap-of-17-days-posting-a-so-siu4 | 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-11-08T18:43:52.178887+00:00 | 2024-11-08T18:43:52.178928+00:00 | 17 | 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-balanced-string | [C++] Short and clean solution | c-short-and-clean-solution-by-bora_maria-tp5k | Use a vector/array of size 2. v[0] will be sum of even position digits, v[1] will be sum of odd position digits.The result will be v[0] == v[1]\n# Code\ncpp []\ | bora_marian | NORMAL | 2024-11-08T07:45:51.100384+00:00 | 2024-11-08T07:45:51.100417+00:00 | 19 | false | Use a vector/array of size 2. ```v[0]``` will be sum of even position digits, ```v[1]``` will be sum of odd position digits.The result will be ```v[0] == v[1]```\n# Code\n```cpp []\nclass Solution {\npublic:\n bool isBalanced(string num) {\n vector<int>v(2, 0);\n for (int i = 0; i < num.size(); i++) {\... | 1 | 0 | ['C++'] | 0 |
check-balanced-string | Assembly with explanation and comparison with C | assembly-with-explanation-and-comparison-4734 | \n# Rationale\n\nI\'ve solved this LeetCode problem using inline assembly in C. My goal isn\'t to showcase complexity, but rather to challenge myself and deepen | pcardenasb | NORMAL | 2024-11-07T09:22:58.492427+00:00 | 2024-11-07T09:40:00.960250+00:00 | 33 | false | \n# Rationale\n\nI\'ve solved this LeetCode problem using inline assembly in C. My goal isn\'t to showcase complexity, but rather to challenge myself and deepen my understanding of assembly language. \n\nAs a beginner in assembly, I welcome any improvements or comments on my code.\n\nAdditionally, I aim to share insigh... | 1 | 0 | ['C'] | 1 |
check-balanced-string | ✅ Easy Rust Solution | easy-rust-solution-by-erikrios-frbb | \nimpl Solution {\n pub fn is_balanced(num: String) -> bool {\n let mut even = 0;\n let mut odd = 0;\n\n for (i, ch) in num.into_bytes() | erikrios | NORMAL | 2024-11-06T06:45:38.843558+00:00 | 2024-11-06T06:45:38.843605+00:00 | 6 | false | ```\nimpl Solution {\n pub fn is_balanced(num: String) -> bool {\n let mut even = 0;\n let mut odd = 0;\n\n for (i, ch) in num.into_bytes().into_iter().enumerate() {\n let ch = ch - b\'0\';\n if i & 1 == 0 {\n even += ch as usize;\n } else {\n ... | 1 | 0 | ['Rust'] | 1 |
check-balanced-string | maracode | maracode-by-pugazhmara-0xk2 | \n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n# Code\njava []\nclass Solution {\n public boolean isBalanced(String num) {\n | pugazhmara | NORMAL | 2024-11-05T03:43:08.297895+00:00 | 2024-11-05T03:43:08.297916+00:00 | 6 | false | \n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n# Code\n```java []\nclass Solution {\n public boolean isBalanced(String num) {\n int sum1=0,sum2=0,len=num.length();\n for(int i=0,j=1;i<len;i=i+2,j=j+2){\n sum1+=num.charAt(i)-48;\n if(j<len)\n su... | 1 | 0 | ['Java'] | 0 |
check-balanced-string | Best Soln 👌👇 | best-soln-by-ram_saketh-wid9 | 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 compl | Ram_Saketh | NORMAL | 2024-11-04T18:28:45.996077+00:00 | 2024-11-04T18:28:45.996117+00:00 | 6 | false | # 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. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n public boolean isBalanced(St... | 1 | 0 | ['Java'] | 0 |
check-balanced-string | Easy 2 Ways | Sum | Difference | C++ | easy-2-ways-sum-difference-c-by-anubhvsh-dzjn | 1. Sum Approach \n\nTime Complexity - O(N)\nSpace Complexity - O(1)\n\n\nclass Solution {\npublic:\n bool isBalanced(string num) {\n int odd = 0, even | anubhvshrma18 | NORMAL | 2024-11-04T17:20:12.125310+00:00 | 2024-11-04T17:20:12.125340+00:00 | 28 | false | ### 1. Sum Approach \n\n*Time Complexity - O(N)*\n*Space Complexity - O(1)*\n\n```\nclass Solution {\npublic:\n bool isBalanced(string num) {\n int odd = 0, even = 0;\n for(int i=0;i<num.length();i++) {\n if(i%2 == 0) {\n even += (num[i]-\'0\');\n } else {\n ... | 1 | 0 | ['Math', 'String', 'C', 'Iterator'] | 0 |
check-balanced-string | Adding to two variables on index | adding-to-two-variables-on-index-by-hari-0z95 | 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 | hari04204 | NORMAL | 2024-11-04T16:44:26.316928+00:00 | 2024-11-04T16:44:26.316975+00:00 | 27 | 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)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$... | 1 | 0 | ['Java'] | 1 |
check-balanced-string | Easy C++ Solution || 100% beat || O(n) complexity | easy-c-solution-100-beat-on-complexity-b-42wl | Intuition\nTo determine if a string of digits is "balanced," we can separate the string into digits at even and odd indices. Summing the digits in these two gro | Sanskruti-Dhal | NORMAL | 2024-11-04T15:26:44.462033+00:00 | 2024-11-04T15:26:44.462066+00:00 | 11 | false | # Intuition\nTo determine if a string of digits is "balanced," we can separate the string into digits at even and odd indices. Summing the digits in these two groups lets us compare the sums to see if they are equal.\n\n# Approach\n1. Initialize two variables, evesum and oddsum, to store the sum of digits at even and o... | 1 | 0 | ['C++'] | 1 |
check-balanced-string | fold | fold-by-user5285zn-j6dc | We compute the sum of the digits where the odd positions are weighted with $-1$.\n\nrust []\nimpl Solution {\n pub fn is_balanced(num: String) -> bool {\n | user5285Zn | NORMAL | 2024-11-04T08:58:21.105338+00:00 | 2024-11-04T08:58:21.105393+00:00 | 2 | false | We compute the sum of the digits where the odd positions are weighted with $-1$.\n\n```rust []\nimpl Solution {\n pub fn is_balanced(num: String) -> bool {\n num.chars().fold((0, 1), |(s, f),d|\n (s+f*(d as i32 - \'0\' as i32), -f)\n ).0 == 0\n }\n}\n``` | 1 | 0 | ['Rust'] | 0 |
check-balanced-string | Java simple solution | java-simple-solution-by-bijoysingh7-okuu | If you found this helpful, an upvote would be appreciated! \uD83D\uDE0A\n# Java Code\njava\nclass Solution {\n public boolean isBalanced(String num) {\n | BijoySingh7 | NORMAL | 2024-11-04T03:45:48.987830+00:00 | 2024-11-04T03:45:48.987873+00:00 | 29 | false | If you found this helpful, an upvote would be appreciated! \uD83D\uDE0A\n# Java Code\n```java\nclass Solution {\n public boolean isBalanced(String num) {\n int oddSum = 0;\n int evenSum = 0;\n\n for (int i = 0; i < num.length(); i++) {\n int digit = num.charAt(i) - \'0\';\n ... | 1 | 0 | ['String', 'Java'] | 0 |
check-balanced-string | ➡️ One line solution. TC: O(n) | one-line-solution-tc-on-by-m3f-vpyz | # Intuition \n\n\n\n\n\n# Complexity\n- Time complexity: O(n)\n\n\n- Space complexity: O(n)\n\n\n# Code\njavascript []\n/**\n * @param {string} num\n * @retur | M3f | NORMAL | 2024-11-03T13:38:38.849629+00:00 | 2024-11-04T13:59:27.510463+00:00 | 106 | 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 spa... | 1 | 0 | ['JavaScript'] | 1 |
check-balanced-string | easy solution | beats 100% | easy-solution-beats-100-by-leet1101-8ofg | Intuition\nTo determine if the string num is balanced, we need to separate the digits at even and odd indices, calculate the sum of each group, and check if the | leet1101 | NORMAL | 2024-11-03T07:53:56.217393+00:00 | 2024-11-03T07:53:56.217419+00:00 | 28 | false | # Intuition\nTo determine if the string `num` is balanced, we need to separate the digits at even and odd indices, calculate the sum of each group, and check if they are equal.\n\n# Approach\n1. Initialize `even` and `odd` sums to zero.\n2. Traverse each character in the string:\n - If the index is even, add the inte... | 1 | 0 | ['C++'] | 0 |
check-balanced-string | Python 1 liner | python-1-liner-by-worker-bee-twxs | Intuition\n\neasy one liner\n\n# Code\npython3 []\nclass Solution:\n def isBalanced(self, num: str) -> bool:\n\n return sum([int(x) for i,x in enumera | worker-bee | NORMAL | 2024-11-03T04:07:08.612414+00:00 | 2024-11-03T04:07:08.612441+00:00 | 107 | false | # Intuition\n\neasy one liner\n\n# Code\n```python3 []\nclass Solution:\n def isBalanced(self, num: str) -> bool:\n\n return sum([int(x) for i,x in enumerate(num) if i%2 == 1 ]) == sum([int(x) for i,x in enumerate(num) if i%2 == 0 ])\n \n``` | 1 | 0 | ['Python3'] | 2 |
check-balanced-string | c++ solution | c-solution-by-dilipsuthar60-vyxg | \nclass Solution {\npublic:\n bool isBalanced(string num) {\n int n=num.size();\n int sum=0;\n for(int i=0;i<n;i++){\n if(i&1 | dilipsuthar17 | NORMAL | 2024-11-03T04:02:10.396075+00:00 | 2024-11-03T04:02:10.396103+00:00 | 40 | false | ```\nclass Solution {\npublic:\n bool isBalanced(string num) {\n int n=num.size();\n int sum=0;\n for(int i=0;i<n;i++){\n if(i&1){\n sum-=(num[i]-\'0\');\n }\n else{\n sum+=(num[i]-\'0\');\n }\n }\n return su... | 1 | 0 | ['C', 'C++'] | 0 |
check-balanced-string | Easy to Understand || Beats 100% in C++ & Python || C++, Java, Python | easy-to-understand-beats-100-in-c-python-0fgx | null | anubhav_py | NORMAL | 2024-12-11T12:06:14.149838+00:00 | 2024-12-11T12:06:14.149838+00:00 | 62 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Screenshot\n\n\n$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['JavaScript'] | 0 |
check-balanced-string | Simple C++ solution by traversing the string. | simple-c-solution-by-traversing-the-stri-ht83 | Complexity
Time complexity:O(N)
Space complexity:O(1)
Code | vansh16 | NORMAL | 2025-04-10T10:47:14.968972+00:00 | 2025-04-10T10:47:14.968972+00:00 | 1 | false |
# Complexity
- Time complexity:O(N)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:O(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```cpp []
class Solution {
public:
bool isBalanced(string num) {
int sumo=0,sume=0;
for(int i=0;i<num.size();i++)
... | 0 | 0 | ['String', 'C++'] | 0 |
check-balanced-string | java | java-by-xyza41004-6dqo | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | xyza41004 | NORMAL | 2025-04-10T09:06:54.672656+00:00 | 2025-04-10T09:06:54.672656+00:00 | 1 | 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
`... | 0 | 0 | ['Java'] | 0 |
check-balanced-string | time complexity O(n), and no extra memory | time-complexity-on-and-no-extra-memory-b-gybs | IntuitionWe do need to use extra space because all digits has to sum up and the result should be zero, as long as even digits is positive and odd digits are neg | bear-with-me | NORMAL | 2025-04-10T06:27:02.358018+00:00 | 2025-04-10T06:27:02.358018+00:00 | 1 | false | # Intuition
We do need to use extra space because all digits has to sum up and the result should be zero, as long as even digits is positive and odd digits are negative
# Approach
Recursivily return the next digit with the correct signal (positive or negative) to sum up all digits at the and
# Complexity
- Time compl... | 0 | 0 | ['Python3'] | 0 |
check-balanced-string | isBalanced with a conversion solution from rune to int | isbalanced-with-a-conversion-solution-fr-rcpf | Complexity
Time complexity: O(n)
Space complexity: O(1)
Code | 44437 | NORMAL | 2025-04-07T16:56:29.527342+00:00 | 2025-04-07T16:56:29.527342+00:00 | 1 | false |
# Complexity
- Time complexity: $$O(n)$$
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity: $$O(1)$$
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```golang []
func isBalanced(num string) bool {
var even int
var odd int
for i, v := range num {
value := int(... | 0 | 0 | ['Go'] | 0 |
check-balanced-string | Sum the odd and even in two variables, and just compare it | sum-the-odd-and-even-in-two-variables-an-377n | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | vikas26061995 | NORMAL | 2025-04-06T12:52:52.730491+00:00 | 2025-04-06T12:52:52.730491+00:00 | 2 | 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
`... | 0 | 0 | ['JavaScript'] | 0 |
check-balanced-string | Beats 100% - Simple Method | beats-100-simple-method-by-siva12443-n6wt | Code | Siva12443 | NORMAL | 2025-04-03T07:17:53.795295+00:00 | 2025-04-03T07:17:53.795295+00:00 | 1 | false | # Code
```javascript []
/**
* @param {string} num
* @return {boolean}
*/
var isBalanced = function(num) {
let even = 0;
let odd = 0;
for(let i = 0; i < num.length; i+=2){
even += parseInt(num[i])
}
for(let j = 1; j < num.length; j+=2 ){
odd += parseInt(num[j])
}
if(even... | 0 | 0 | ['JavaScript'] | 0 |
check-balanced-string | C# | c-by-m093020099-x3lo | IntuitionApproachComplexity
Time complexity:O(n)
Space complexity:O(1)
Code | m093020099 | NORMAL | 2025-04-02T16:55:17.938984+00:00 | 2025-04-02T16:55:17.938984+00:00 | 2 | 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(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
... | 0 | 0 | ['C#'] | 0 |
check-balanced-string | python solved code | python-solved-code-by-archananagaraj-vmy5 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | archananagaraj | NORMAL | 2025-04-02T06:12:45.177623+00:00 | 2025-04-02T06:12:45.177623+00:00 | 1 | 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
`... | 0 | 0 | ['Python'] | 0 |
check-balanced-string | Ruby Solution | ruby-solution-by-kishorecheruku-rfe7 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | kishorecheruku | NORMAL | 2025-04-01T02:03:49.880002+00:00 | 2025-04-01T02:03:49.880002+00:00 | 1 | 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
`... | 0 | 0 | ['Ruby'] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.