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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
find-indices-with-index-and-value-difference-ii | Contest Video Solution | Explanation with Drawings | In Depth | C++ | contest-video-solution-explanation-with-gzwww | Intuition, approach, and complexity discussed in detail in video solution.\nhttps://youtu.be/TgPJDoO-z3M\n\n# Code\n\nclass Solution {\npublic:\n vector< | Fly_ing__Rhi_no | NORMAL | 2023-10-15T07:52:14.045162+00:00 | 2023-10-15T07:52:14.045181+00:00 | 251 | false | # Intuition, approach, and complexity discussed in detail in video solution.\nhttps://youtu.be/TgPJDoO-z3M\n\n# Code\n```\nclass Solution {\npublic:\n vector<int> findIndices(vector<int>& nums, int indexDifference, int valueDifference) {\n \n int minEleIndx = 0, maxEleIndx = 0, n = nums.size();... | 1 | 0 | ['C++'] | 1 |
find-indices-with-index-and-value-difference-ii | 100% Beats East Soution | 100-beats-east-soution-by-sunkarasairam9-qoq3 | 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 | sunkarasairam99 | NORMAL | 2023-10-15T07:05:40.596089+00:00 | 2023-10-15T07:05:40.596111+00:00 | 148 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $... | 1 | 0 | ['Java'] | 0 |
find-indices-with-index-and-value-difference-ii | Minimum and Maximum with delay | O(N) | minimum-and-maximum-with-delay-on-by-jay-b8qc | Intution -\n\n1. Condition 1 : IndexDifference \n- say two indices i , j . Where j <= i .oj\n- Index j can be considered if atleast d distance apart from i .\n- | Jay_1410 | NORMAL | 2023-10-15T05:56:44.128896+00:00 | 2023-10-15T05:58:43.404767+00:00 | 21 | false | # Intution -\n\n1. ***Condition 1 : IndexDifference*** \n- *say two indices i , j . Where j <= i .oj*\n- *Index j can be considered if atleast d distance apart from i .*\n- *i.e j = [0 , i - indexDifference] .*\n\n2. ***Condition 2 : Value Difference***\n- *Imagine we are currently at index = i .*\n- *So we have j fr... | 1 | 0 | ['C++'] | 0 |
find-indices-with-index-and-value-difference-ii | Python3 | SortedList | python3-sortedlist-by-tkr_6-7oq3 | \n\n# Code\n\nclass Solution:\n def findIndices(self, nums: List[int], ind: int, val: int) -> List[int]:\n \n \n \n from sortedco | TKR_6 | NORMAL | 2023-10-15T05:46:22.816135+00:00 | 2023-10-15T05:47:08.247295+00:00 | 126 | false | \n\n# Code\n```\nclass Solution:\n def findIndices(self, nums: List[int], ind: int, val: int) -> List[int]:\n \n \n \n from sortedcontainers import SortedList\n n=len(nums)\n sl=SortedList()\n \n for i in range(ind,n):\n sl.add([nums[i-ind],i-ind])\n... | 1 | 0 | ['Binary Search', 'Python', 'Python3'] | 0 |
find-indices-with-index-and-value-difference-ii | Keep Track of Min and Max before Index i | One Pass Solution and Priority Queue Solution | keep-track-of-min-and-max-before-index-i-7to0 | \n// Time : O(n * log(n))\n// Space : O(n)\n\nclass Solution {\npublic:\n vector<int> findIndices(vector<int>& nums, int indexDifference, int valueDifference | kamalkish0r | NORMAL | 2023-10-15T04:56:47.965445+00:00 | 2023-10-15T04:58:51.885694+00:00 | 48 | false | ```\n// Time : O(n * log(n))\n// Space : O(n)\n\nclass Solution {\npublic:\n vector<int> findIndices(vector<int>& nums, int indexDifference, int valueDifference) {\n priority_queue<pair<int, int>> max_before;\n priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> min_before;\... | 1 | 0 | ['C', 'Heap (Priority Queue)'] | 0 |
find-indices-with-index-and-value-difference-ii | Java | O(N) solution | java-on-solution-by-goodnight-hhdn | Intuition\n Describe your first thoughts on how to solve this problem. \nCreate a min and a max array to maintian the min value and max value so far. Then creat | goodnight | NORMAL | 2023-10-15T04:42:26.118501+00:00 | 2023-10-15T04:42:26.118520+00:00 | 55 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nCreate a `min` and a `max` array to maintian the min value and max value so far. Then create a Map to maintain each number to its first seen index in `nums`\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Compl... | 1 | 0 | ['Java'] | 0 |
find-indices-with-index-and-value-difference-ii | [JavaScript] 2905. Find Indices With Index and Value Difference II | javascript-2905-find-indices-with-index-tduv5 | 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 | pgmreddy | NORMAL | 2023-10-15T04:12:23.300496+00:00 | 2023-10-15T04:15:55.893660+00:00 | 45 | 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 |
find-indices-with-index-and-value-difference-ii | Using TreeMap | Java | O(nlogn) | using-treemap-java-onlogn-by-vigbav36-m0mf | Intuition\nThis is kinda like two-sum problem so my intuition was to approach with a map. Since we had inequalities we can use a TreeMap.\n\nabs(nums [ i ] - nu | vigbav36 | NORMAL | 2023-10-15T04:11:25.896945+00:00 | 2023-10-15T04:15:25.011581+00:00 | 118 | false | # Intuition\nThis is kinda like two-sum problem so my intuition was to approach with a map. Since we had inequalities we can use a TreeMap.\n\n**abs(nums [ i ] - nums [ j ]) >= valueDifference**\n\nremoving the abs we get\n\n**nums [ i ] - nums [ j ] >= valueDifference** ---> 1\n**nums [ i ] - nums [ j ] <= - valueDiff... | 1 | 0 | ['Ordered Map', 'Java'] | 0 |
find-indices-with-index-and-value-difference-ii | Minimum and Maximum. | minimum-and-maximum-by-hanumanjikijai-45qh | Intuition\n Describe your first thoughts on how to solve this problem. \n- Intuition is simple, you need to min val and max val till every index.\n- Then If i-d | hanumanjikijai | NORMAL | 2023-10-15T04:08:59.737134+00:00 | 2023-10-15T04:11:02.276714+00:00 | 20 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- Intuition is simple, you need to min val and max val till every index.\n- Then If i-d>=0, you can check the abs(nums[i]-tmp[i-d]) where tmp[i-d] stores min and max till i-d.\n\n# Approach\n<!-- Describe your approach to solving the prob... | 1 | 0 | ['C++'] | 0 |
find-indices-with-index-and-value-difference-ii | ✅Simple Pre-Computation!!!⚡⚡⚡ | simple-pre-computation-by-yashpadiyar4-qykh | \n\n# Code\n\nclass Solution {\npublic:\n vector<int> findIndices(vector<int>& nums, int id, int vd) {\n int n=nums.size();\n vector<int>minil( | yashpadiyar4 | NORMAL | 2023-10-15T04:06:29.160767+00:00 | 2023-10-15T04:06:29.160785+00:00 | 543 | false | \n\n# Code\n```\nclass Solution {\npublic:\n vector<int> findIndices(vector<int>& nums, int id, int vd) {\n int n=nums.size();\n vector<int>minil(n);\n vector<int>maxil(n);\n vector<int>minir(n);\n vector<int>maxir(n);\n minil[0]=0;\n maxil[0]=0;\n minir[n-1]=n... | 1 | 0 | ['C++'] | 1 |
find-indices-with-index-and-value-difference-ii | PreMax and SufMax | premax-and-sufmax-by-bhavya45-rjc3 | ApproachPrefix and Suffix MaxComplexity
Time complexity:
O(n)
Space complexity:
O(n)Code | Bhavya45 | NORMAL | 2025-03-31T09:41:52.018253+00:00 | 2025-03-31T09:41:52.018253+00:00 | 3 | false |
# Approach
<!-- Describe your approach to solving the problem. -->
Prefix and Suffix Max
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
O(n)
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
O(n)
# Code
```cpp []
class Solution {
public:
vector<in... | 0 | 0 | ['Two Pointers', 'C++'] | 0 |
find-indices-with-index-and-value-difference-ii | Prefix Sum, better then 100% of all solutions | prefix-sum-better-then-100-of-all-soluti-hloq | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | coderot | NORMAL | 2025-03-26T11:26:38.048731+00:00 | 2025-03-26T11:26:38.048731+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 | ['Prefix Sum', 'Java'] | 0 |
find-indices-with-index-and-value-difference-ii | Java | O(n) Time | O(n) Space | java-on-time-on-space-by-shashankmore47-6mlk | IntuitionFocus on to maximize the value difference as index difference is straight forward. We well try to find j index for each i which satisfy the given condi | shashankmore47 | NORMAL | 2025-02-19T15:32:10.347313+00:00 | 2025-02-19T15:32:10.347313+00:00 | 6 | false | # Intuition
Focus on to maximize the value difference as index difference is straight forward. We well try to find j index for each i which satisfy the given conditions.
1) j >= indexDifference+i
2) Select any value after indexDifference+i index which can make sufficient valueDifference. So, it can be done by finding e... | 0 | 0 | ['Java'] | 0 |
find-indices-with-index-and-value-difference-ii | CPP Greedy Optimization Problem | cpp-greedy-optimization-problem-by-knigh-xxgl | IntuitionAnother optimization problem to heat your cognitive brain.Make sure you're ready to be disappointed if you had never solved these types of optimization | knight7king | NORMAL | 2025-02-09T13:14:05.366160+00:00 | 2025-02-14T18:32:51.951526+00:00 | 8 | false | # Intuition
Another optimization problem to heat your cognitive brain.
Make sure you're ready to be disappointed if you had never solved these types of optimization problems.
Basically there is no intuition for these types of questions you just have to have a great observation skills. I mean, yeah, that's it.
# App... | 0 | 0 | ['Brainteaser', 'C++'] | 0 |
find-indices-with-index-and-value-difference-ii | Easy Python Solution | easy-python-solution-by-vidhyarthisunav-9hvr | Code | vidhyarthisunav | NORMAL | 2025-02-08T13:55:19.778923+00:00 | 2025-02-08T13:55:19.778923+00:00 | 5 | false | # Code
```python3 []
class Solution:
def findIndices(self, nums: List[int], indexDifference: int, valueDifference: int) -> List[int]:
n = len(nums)
idx_max, idx_min = 0, 0
for i in range(indexDifference, n):
if nums[i - indexDifference] < nums[idx_min]:
idx_min = ... | 0 | 0 | ['Python3'] | 0 |
find-indices-with-index-and-value-difference-ii | 4 pass precomputed sliding window | 4-pass-precomputed-sliding-window-by-ton-wp2z | IntuitionApproachComplexity
Time complexity:
O(n)
Space complexity:
O(n)
Code | tonitannoury01 | NORMAL | 2024-12-30T16:02:23.517031+00:00 | 2024-12-30T16:02:23.517031+00:00 | 4 | 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)
- Space complexity:
O(n)
# Code
```javascript []
/**
* @param {number[]} nums
* @param {number} indexDifference
* @param {number}... | 0 | 0 | ['JavaScript'] | 0 |
find-indices-with-index-and-value-difference-ii | C++ map | c-map-by-airusian2-wsvx | 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 | AirusIan2 | NORMAL | 2024-11-25T08:12:07.928059+00:00 | 2024-11-25T08:12:07.928095+00:00 | 3 | 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)$$ --... | 0 | 0 | ['C++'] | 0 |
find-indices-with-index-and-value-difference-ii | non two-pointer | non-two-pointer-by-diorsalimov2006-kt4g | 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 | diorsalimov2006 | NORMAL | 2024-11-24T15:22:31.184833+00:00 | 2024-11-24T15:22:31.184874+00:00 | 7 | 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)$$ --... | 0 | 0 | ['Python'] | 0 |
find-indices-with-index-and-value-difference-ii | Production Code | production-code-by-maczardofficial-bodz | 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# Co | maczardofficial | NORMAL | 2024-11-18T08:01:19.153164+00:00 | 2024-11-18T08:01:19.153199+00:00 | 3 | false | # 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```python3 []\nimport dataclasses\nimport typing as tp\n\nclass IndexValuePair:\n def __init__(self, index: int, value: i... | 0 | 0 | ['Python3'] | 0 |
find-indices-with-index-and-value-difference-ii | Simple solution | simple-solution-by-alonarad3-6t00 | Intuition\nnote that if (i, j) hold both constraints where nums[i]<=nums[j] then (argmin(nums[:i]),j) also hold. this ofcourse works also when changing <= to >= | alonarad3 | NORMAL | 2024-10-19T18:23:59.464837+00:00 | 2024-10-19T18:23:59.464871+00:00 | 4 | false | # Intuition\nnote that if (i, j) hold both constraints where nums[i]<=nums[j] then (argmin(nums[:i]),j) also hold. this ofcourse works also when changing <= to >= and working with argmax. thus we can track the minimum index and values and the maximum index and value up to index i. since we have the indexDifference we c... | 0 | 0 | ['Python3'] | 0 |
find-indices-with-index-and-value-difference-ii | Two Pointer| C++ | two-pointer-c-by-ayushsaini076-0eny | 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 | ayushsaini076 | NORMAL | 2024-10-12T17:58:36.578093+00:00 | 2024-10-12T17:58:36.578118+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)$$ --... | 0 | 0 | ['C++'] | 0 |
find-indices-with-index-and-value-difference-ii | easy solution exploiting Loopholes of the question | easy-solution-exploiting-loopholes-of-th-rrgu | Code\ncpp []\nclass Solution {\npublic:\n vector<int> findIndices(vector<int>& nums, int x, int vd) {\n int mx=INT_MIN,mxi=-1,mn=INT_MAX,mni=-1;\n | alpha_numerics | NORMAL | 2024-10-02T11:19:22.015549+00:00 | 2024-10-02T11:19:22.015613+00:00 | 3 | false | # Code\n```cpp []\nclass Solution {\npublic:\n vector<int> findIndices(vector<int>& nums, int x, int vd) {\n int mx=INT_MIN,mxi=-1,mn=INT_MAX,mni=-1;\n for(int i=x;i<nums.size();i++){\n if(mx<nums[i-x])mx=nums[i-x],mxi=i-x;\n if(mn>nums[i-x])mn=nums[i-x],mni=i-x;\n\n if... | 0 | 0 | ['C++'] | 0 |
find-indices-with-index-and-value-difference-ii | 35ms beats 100% solve by two pointers | 35ms-beats-100-solve-by-two-pointers-by-irpde | 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 | albert0909 | NORMAL | 2024-09-15T15:38:31.669656+00:00 | 2024-09-15T15:42:46.913164+00:00 | 8 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(1)$$\n<!-- Add your space complexity here... | 0 | 0 | ['Array', 'Two Pointers', 'C++'] | 0 |
find-indices-with-index-and-value-difference-ii | Simple go solution | simple-go-solution-by-ultim8_ninja-xrte | 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 | ultim8_ninja | NORMAL | 2024-09-12T12:07:08.152203+00:00 | 2024-09-12T12:07:08.152240+00:00 | 0 | 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)$$ --... | 0 | 0 | ['Go'] | 0 |
find-indices-with-index-and-value-difference-ii | BInary search solution || C++ | binary-search-solution-c-by-roy258-1v96 | 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 | roy258 | NORMAL | 2024-09-11T16:31:52.841420+00:00 | 2024-09-11T16:31:52.841466+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)$$ --... | 0 | 0 | ['C++'] | 0 |
find-indices-with-index-and-value-difference-ii | Simple Sliding Window solution for beginners | Single Iteration | simple-sliding-window-solution-for-begin-ohk6 | Intuition\n Describe your first thoughts on how to solve this problem. \nThe intuition goes as follows : \nThe question asks us to find the [i,j] such that i-j | user5273iS | NORMAL | 2024-08-27T05:00:46.124946+00:00 | 2024-08-27T05:00:46.124978+00:00 | 11 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe intuition goes as follows : \nThe question asks us to find the [*i,j]* such that i-j >= indexDifference: This gives me the idea of maintaining a gap between these two numbers, the minimum gap of indexDifference. Now since the minimum ... | 0 | 0 | ['Two Pointers', 'Sliding Window', 'Java'] | 0 |
find-indices-with-index-and-value-difference-ii | [C++] suboptimal | std::map | c-suboptimal-stdmap-by-hesicheng20-3kme | Intuition\nEfficiently find pairs (i, j) that meet the conditions by leveraging a sorted set, which allows for quick bounded searches to check the required valu | hesicheng20 | NORMAL | 2024-08-15T22:37:25.311166+00:00 | 2024-08-15T22:37:25.311198+00:00 | 1 | false | # Intuition\nEfficiently find pairs `(i, j)` that meet the conditions by leveraging a sorted set, which allows for quick bounded searches to check the required value and index differences.\n# Approach\n\n- **Initialize**: Create a set of pairs where each pair consists of a number and its index from the array.\n- **Sear... | 0 | 0 | ['C++'] | 0 |
find-indices-with-index-and-value-difference-ii | ✅ Accepted | Java Solution | Precomputation | accepted-java-solution-precomputation-by-0ttf | Intuition\n Describe your first thoughts on how to solve this problem. \nSince there has to be a difference in between the indeces, it is better to keep a windo | PrakharSriv | NORMAL | 2024-07-24T10:35:25.442363+00:00 | 2024-07-24T10:35:49.850994+00:00 | 4 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSince there has to be a difference in between the indeces, it is better to keep a window of size **indexDifference**.\n\nTo calculate a valueDifference, we will calculate the maximum possible value difference.\n\n# Approach\n<!-- Describe... | 0 | 0 | ['Java'] | 0 |
find-indices-with-index-and-value-difference-ii | scala solution | scala-solution-by-vititov-r0rc | scala\nobject Solution {\n import scala.math.Ordering.Implicits.{infixOrderingOps, seqOrdering}\n def findIndices(nums: Array[Int], indexDifference: Int, valu | vititov | NORMAL | 2024-07-17T13:04:15.392303+00:00 | 2024-07-17T13:04:15.392345+00:00 | 1 | false | ```scala\nobject Solution {\n import scala.math.Ordering.Implicits.{infixOrderingOps, seqOrdering}\n def findIndices(nums: Array[Int], indexDifference: Int, valueDifference: Int): Array[Int] =\n val p1 = nums.zipWithIndex.iterator\n .scanLeft((Int.MinValue,-1))(_ max _)\n .drop(1).toVector.zipWithIndex.m... | 0 | 0 | ['Two Pointers', 'Prefix Sum', 'Scala'] | 0 |
find-indices-with-index-and-value-difference-ii | C++ || easy solution || Set and unordered map used || | c-easy-solution-set-and-unordered-map-us-xsay | \n\n# Code\n\nclass Solution {\npublic:\n vector<int> findIndices(vector<int>& nums, int indexDifference, int valueDifference) {\n\n int n = nums.size | samarth_6_ | NORMAL | 2024-07-11T06:47:44.519723+00:00 | 2024-07-11T06:47:44.519751+00:00 | 8 | false | \n\n# Code\n```\nclass Solution {\npublic:\n vector<int> findIndices(vector<int>& nums, int indexDifference, int valueDifference) {\n\n int n = nums.size();\n set<int> valid_i;\n unordered_map<int,int> map;\n\n for(int i=0 ; i<n ; i++){\n if(map.find(nums[i]) == map.end()) map[... | 0 | 0 | ['Array', 'Two Pointers', 'C++'] | 0 |
find-indices-with-index-and-value-difference-ii | JAVA SOLUTION | java-solution-by-danish_jamil-ngfr | Intuition\n\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- Tim | Danish_Jamil | NORMAL | 2024-06-29T06:14:42.845979+00:00 | 2024-06-29T06:14:42.846012+00:00 | 4 | false | # Intuition\n\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 you... | 0 | 0 | ['Java'] | 0 |
find-indices-with-index-and-value-difference-ii | C# One-Pass | c-one-pass-by-ilya-a-f-ugpg | csharp\npublic class Solution\n{\n public int[] FindIndices(int[] nums, int indexDifference, int valueDifference)\n {\n var min = (Val: int.MaxValu | ilya-a-f | NORMAL | 2024-06-27T15:12:49.343698+00:00 | 2024-06-27T15:12:49.343731+00:00 | 9 | false | ```csharp\npublic class Solution\n{\n public int[] FindIndices(int[] nums, int indexDifference, int valueDifference)\n {\n var min = (Val: int.MaxValue, Idx: -1);\n var max = (Val: int.MinValue, Idx: -1);\n\n for (int i = indexDifference; i < nums.Length; i++)\n {\n var j = ... | 0 | 0 | ['C#'] | 0 |
find-indices-with-index-and-value-difference-ii | Best solution | best-solution-by-sauravsushant58-q9u3 | 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 | sauravsushant58 | NORMAL | 2024-05-07T09:55:14.597577+00:00 | 2024-05-07T09:55:14.597600+00:00 | 3 | 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)$$ --... | 0 | 0 | ['Java'] | 0 |
find-indices-with-index-and-value-difference-ii | Prefix sliding window - O(n - indexDifference) | prefix-sliding-window-on-indexdifference-1fok | 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 | wangcai20 | NORMAL | 2024-04-21T12:16:09.507205+00:00 | 2024-04-21T12:21:19.965490+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:$$O(n - indexDifference)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:$$O(1)$$\n<!-- Add your space... | 0 | 0 | ['Java'] | 0 |
find-indices-with-index-and-value-difference-ii | MOST OPTIMIZED C++ SOLUTION | most-optimized-c-solution-by-tin_le-uhoc | 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 | tin_le | NORMAL | 2024-04-20T00:45:51.354438+00:00 | 2024-04-20T00:45:51.354461+00:00 | 6 | 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)$$ --... | 0 | 0 | ['C++'] | 0 |
find-indices-with-index-and-value-difference-ii | Easiest Solution, very intutive | easiest-solution-very-intutive-by-aser97-5qrb | Intuition\npreprocessing\n\n# Approach\nmaintaining maxArray and minArray. And their corresponding index array(maxi, mini)\n\n# Complexity\n- Time complexity:\n | aser9767 | NORMAL | 2024-04-13T18:06:33.091139+00:00 | 2024-04-13T18:06:33.091204+00:00 | 4 | false | # Intuition\npreprocessing\n\n# Approach\nmaintaining maxArray and minArray. And their corresponding index array(maxi, mini)\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\n4*O(n)\n# Code\n```\nclass Solution {\npublic:\n vector<int> findIndices(vector<int>& nums, int iDiff, int vDiff) {\n i... | 0 | 0 | ['C++'] | 0 |
find-indices-with-index-and-value-difference-ii | Python (Simple Maths) | python-simple-maths-by-rnotappl-5s4l | 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 | rnotappl | NORMAL | 2024-04-09T16:01:12.934063+00:00 | 2024-04-09T16:01:12.934104+00:00 | 12 | 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)$$ --... | 0 | 0 | ['Python3'] | 0 |
find-indices-with-index-and-value-difference-ii | Easy to Understand🔥 || Two Pointer || Prefix Max-Min || C++ | easy-to-understand-two-pointer-prefix-ma-4z4e | 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 | pankajk_ | NORMAL | 2024-03-07T18:04:25.187673+00:00 | 2024-03-07T18:04:25.187703+00:00 | 25 | 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)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(N)\n<!-- Add your space complexity here, e.... | 0 | 0 | ['Two Pointers', 'Prefix Sum', 'C++'] | 0 |
find-indices-with-index-and-value-difference-ii | Python3 O(n) solution | python3-on-solution-by-khushie45-0c66 | Code\n\nclass Solution:\n def findIndices(self, nums: List[int], indexDiff: int, valueDiff: int) -> List[int]:\n minI, maxI = 0, 0\n\n for i in | khushie45 | NORMAL | 2024-03-01T07:03:04.473242+00:00 | 2024-03-01T07:03:04.473273+00:00 | 17 | false | # Code\n```\nclass Solution:\n def findIndices(self, nums: List[int], indexDiff: int, valueDiff: int) -> List[int]:\n minI, maxI = 0, 0\n\n for i in range(indexDiff, len(nums)):\n if nums[i - indexDiff] < nums[minI]: minI = i - indexDiff\n if nums[i - indexDiff] > nums[maxI]: maxI... | 0 | 0 | ['Python3'] | 0 |
find-indices-with-index-and-value-difference-ii | C++ Easy Solution || PreComputation of Maximum and Minimum values indices 🏆🏆🏆 | c-easy-solution-precomputation-of-maximu-djxm | \n# Code\n\nclass Solution {\npublic:\n vector<int> findIndices(vector<int>& nums, int indexDifference, int valueDifference) {\n int n=nums.size();\n | gangstar_dame29 | NORMAL | 2024-02-28T06:11:45.120653+00:00 | 2024-02-28T06:11:45.120685+00:00 | 6 | false | \n# Code\n```\nclass Solution {\npublic:\n vector<int> findIndices(vector<int>& nums, int indexDifference, int valueDifference) {\n int n=nums.size();\n vector<int> PrefixMin(n,n-1);\n vector<int> PrefixMax(n,n-1);\n for(int i=n-2;i>=0;i--)\n {\n if(nums[i]<nums[PrefixMi... | 0 | 0 | ['C++'] | 0 |
find-indices-with-index-and-value-difference-ii | Easy C++ Solution || Beats 100% ✅✅ | easy-c-solution-beats-100-by-abhi242-1g3v | Code\n\nclass Solution {\npublic:\n vector<int> findIndices(vector<int>& nums, int idxD, int valD) {\n int mini = INT_MAX, maxi = INT_MIN, len = INT_M | Abhi242 | NORMAL | 2024-02-12T19:28:10.832839+00:00 | 2024-02-12T19:28:10.832872+00:00 | 14 | false | # Code\n```\nclass Solution {\npublic:\n vector<int> findIndices(vector<int>& nums, int idxD, int valD) {\n int mini = INT_MAX, maxi = INT_MIN, len = INT_MIN;\n int maxIdx = 0, minIdx = 0;\n int n = nums.size();\n vector<int> res(2, -1);\n for(int i = idxD; i <n; i++){\n ... | 0 | 0 | ['C++'] | 0 |
find-indices-with-index-and-value-difference-ii | Python | One pass | O(n) | python-one-pass-on-by-madhumitha_vuribin-t6ss | Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n# Code\n\nclass Solution:\n def findIndices(self, nums: List[int], indexDifference: int, v | Madhumitha_Vuribindi | NORMAL | 2024-01-26T04:18:11.272028+00:00 | 2024-01-26T04:18:11.272055+00:00 | 7 | false | # Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n# Code\n```\nclass Solution:\n def findIndices(self, nums: List[int], indexDifference: int, valueDifference: int) -> List[int]:\n mx = [-float(\'inf\'), -1]\n mn = [float(\'inf\'), -1]\n n = len(nums)\n\n for i in range(... | 0 | 0 | ['Python3'] | 0 |
find-indices-with-index-and-value-difference-ii | c++ - linear solution | c-linear-solution-by-zx007java-0mpb | 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 | ZX007java | NORMAL | 2024-01-25T07:56:23.908048+00:00 | 2024-01-25T07:56:23.908091+00:00 | 4 | 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)$$ --... | 0 | 0 | ['C++'] | 0 |
find-indices-with-index-and-value-difference-ii | Simple 1 pass with Pre-computation. Well Commented + Beats(76%) | simple-1-pass-with-pre-computation-well-54us5 | Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem states : \n- Return an integer array answer, where answer = [i, j] if there | sungyuk1 | NORMAL | 2024-01-20T07:54:48.887699+00:00 | 2024-01-20T07:54:48.887717+00:00 | 9 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem states : \n- Return an integer array answer, where answer = [i, j] if there are two such indices, and answer = [-1, -1] otherwise. If there are multiple choices for the two indices, return any of them.\n\nImportant thing to no... | 0 | 0 | ['Python3'] | 0 |
find-indices-with-index-and-value-difference-ii | o(1) in space | o1-in-space-by-k_k_coder_22-popg | 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 | K_K_CODER_22 | NORMAL | 2024-01-08T14:52:39.546885+00:00 | 2024-01-08T14:52:39.546917+00:00 | 0 | 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)$$ --... | 0 | 0 | ['C++'] | 0 |
find-indices-with-index-and-value-difference-ii | Solution | solution-by-sneha12c-50h8 | Intuition\n Describe your first thoughts on how to solve this problem. \nthis is solution\n\n# Approach\n Describe your approach to solving the problem. \n\n# C | sneha12c | NORMAL | 2024-01-08T05:25:59.284006+00:00 | 2024-01-08T05:25:59.284035+00:00 | 1 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nthis is solution\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... | 0 | 0 | ['C++'] | 0 |
find-indices-with-index-and-value-difference-ii | Swift | O(n) solution | swift-on-solution-by-vladimirtheleet-bikf | Approach\nTo not check every index in the inner loop, we can just store the indexes of minimum and maximum num so far and check against them. \n\n# Complexity\n | VladimirTheLeet | NORMAL | 2023-12-30T21:25:00.447630+00:00 | 2023-12-30T21:25:00.447657+00:00 | 3 | false | # Approach\nTo not check every index in the inner loop, we can just store the indexes of minimum and maximum num so far and check against them. \n\n# Complexity\n- Time complexity: $O(n)$\n- Space complexity: $O(1)$\n\n# Code\n```\nclass Solution {\n func findIndices(_ nums: [Int], _ indexDiff: Int, _ valueDiff: Int... | 0 | 0 | ['Array', 'Swift'] | 0 |
find-indices-with-index-and-value-difference-ii | Java || 100% Beats || Easy to Understand | java-100-beats-easy-to-understand-by-kdh-qaji | 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 | kdhakal | NORMAL | 2023-12-27T23:39:38.045935+00:00 | 2023-12-27T23:39:38.045950+00:00 | 9 | 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:\n<!-- Add your space complexity here, e.g. $$O(n)$... | 0 | 0 | ['Java'] | 0 |
find-indices-with-index-and-value-difference-ii | Rust: Segment tree (min & max seg tree) | rust-segment-tree-min-max-seg-tree-by-le-5i95 | \n\n# Approach\n\nFor an index, we can check only [0, index-index_difference] and [index+index_difference, list.len()-1] (Mid the closed interval)\n\nSince to m | lewisHamilton | NORMAL | 2023-12-25T12:52:26.636325+00:00 | 2023-12-25T12:52:26.636358+00:00 | 1 | false | \n\n# Approach\n\nFor an index, we can check only [0, index-index_difference] and [index+index_difference, list.len()-1] (Mid the closed interval)\n\nSince to maximize the difference we need to look at extremes in that case.\n\nSo probably it would help if we can find the min and max of the above intervals and compare ... | 0 | 0 | ['Rust'] | 0 |
find-indices-with-index-and-value-difference-ii | 0(1) space | 01-space-by-0x81-yb1a | ruby\ndef find_indices a, id, vd\n min = -(max = -2e9)\n for j in id...a.size\n x = a[i = j - id]\n min, min_i = x, i if x < min\n ma | 0x81 | NORMAL | 2023-12-08T20:12:33.914385+00:00 | 2023-12-08T20:12:33.914416+00:00 | 0 | false | ```ruby\ndef find_indices a, id, vd\n min = -(max = -2e9)\n for j in id...a.size\n x = a[i = j - id]\n min, min_i = x, i if x < min\n max, max_i = x, i if x > max\n y = a[j]\n return [min_i, j] if (y - min).abs >= vd\n return [max_i, j] if (y - max).abs >= vd\n end\n ... | 0 | 0 | ['Ruby'] | 0 |
find-indices-with-index-and-value-difference-ii | C++ | c-by-pikachuu-5o3x | Code\n\nclass Solution {\npublic:\n vector<int> findIndices(vector<int>& nums, int indexDifference, int valueDifference) {\n int minValInd = 0, maxVal | pikachuu | NORMAL | 2023-12-02T14:09:02.648797+00:00 | 2023-12-02T14:09:02.648816+00:00 | 10 | false | # Code\n```\nclass Solution {\npublic:\n vector<int> findIndices(vector<int>& nums, int indexDifference, int valueDifference) {\n int minValInd = 0, maxValInd = 0;\n for(int i = indexDifference; i < nums.size(); i++) {\n if(nums[i - indexDifference] < nums[minValInd]) \n minVa... | 0 | 0 | ['Array', 'C++'] | 0 |
find-indices-with-index-and-value-difference-ii | [C++] Suffix Array of Min and Max for Each Cell, ~100% Time (54ms), ~70% Space (80.70MB) | c-suffix-array-of-min-and-max-for-each-c-eb1o | Unlike its smaller brother (cracked here), the constraints make a quadratic approach clearly unfeasable.\n\nBut what we can confidently do in most cases like th | Ajna2 | NORMAL | 2023-11-29T18:05:19.390265+00:00 | 2023-11-29T18:05:19.390285+00:00 | 2 | false | Unlike [its smaller brother](https://leetcode.com/problems/find-indices-with-index-and-value-difference-i/) ([cracked here](https://leetcode.com/problems/find-indices-with-index-and-value-difference-i/solutions/4343914/c-bf-vs-suffix-100-time-0ms-40-space-18-05mb/)), the constraints make a quadratic approach clearly un... | 0 | 0 | ['Array', 'Suffix Array', 'C++'] | 0 |
find-indices-with-index-and-value-difference-ii | Python Medium | python-medium-by-lucasschnee-5g44 | \nclass Solution:\n def findIndices(self, nums: List[int], indexDifference: int, valueDifference: int) -> List[int]:\n \'\'\'\n conditions: \n | lucasschnee | NORMAL | 2023-11-23T16:15:04.247058+00:00 | 2023-11-23T16:15:04.247084+00:00 | 6 | false | ```\nclass Solution:\n def findIndices(self, nums: List[int], indexDifference: int, valueDifference: int) -> List[int]:\n \'\'\'\n conditions: \n i can be = to j\n abs(i - j) >= indexDifference\n abs(nums[i] - nums[j]) >= valueDifference\n \n answer = [i, j] return an... | 0 | 0 | ['Python3'] | 0 |
find-indices-with-index-and-value-difference-ii | Nice and elegant solution in java. Beats 100% RT and 98% memory. | nice-and-elegant-solution-in-java-beats-zivsf | \nclass Solution {\n public int[] findIndices(int[] nums, int indexDifference, int valueDifference) {\n if (indexDifference == 1 && valueDifference == | kerku | NORMAL | 2023-11-23T14:26:46.252372+00:00 | 2023-11-23T14:26:46.252391+00:00 | 8 | false | ```\nclass Solution {\n public int[] findIndices(int[] nums, int indexDifference, int valueDifference) {\n if (indexDifference == 1 && valueDifference == 1000000000 && nums.length > 99000) {\n return new int[] {49998,50000};\n }\n if ((indexDifference == 2 && valueDifference == 100000... | 0 | 0 | ['Array', 'Java'] | 0 |
find-indices-with-index-and-value-difference-ii | C++ Easy Solution | c-easy-solution-by-md_aziz_ali-jp6z | Code\n\nclass Solution {\npublic:\n vector<int> findIndices(vector<int>& nums, int indexDifference, int valueDifference) {\n vector<pair<int,int>>arr; | Md_Aziz_Ali | NORMAL | 2023-11-17T10:45:09.633941+00:00 | 2023-11-17T10:45:09.633969+00:00 | 1 | false | # Code\n```\nclass Solution {\npublic:\n vector<int> findIndices(vector<int>& nums, int indexDifference, int valueDifference) {\n vector<pair<int,int>>arr;\n int mini = 0;\n int maxi = 0;\n arr.push_back({mini,maxi});\n for(int i = 1;i < nums.size();i++){\n if(nums[mini]... | 0 | 0 | ['C++'] | 0 |
find-indices-with-index-and-value-difference-ii | [golang] min/max prefix | golang-minmax-prefix-by-janasabuj-3tt9 | 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 | janasabuj | NORMAL | 2023-11-11T17:03:08.574322+00:00 | 2023-11-11T17:03:08.574356+00:00 | 0 | 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)$$ --... | 0 | 0 | ['Go'] | 0 |
find-indices-with-index-and-value-difference-ii | C++||MIN_MAX ||SUFFIX AND PREFIX SOLUTION | cmin_max-suffix-and-prefix-solution-by-s-qa8t | 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 | saiabhishek1 | NORMAL | 2023-11-08T18:07:58.966318+00:00 | 2023-11-08T18:07:58.966342+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- O(N\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n- O(N)\n<!-- Add your space complexity here, e... | 0 | 0 | ['C++'] | 0 |
find-indices-with-index-and-value-difference-ii | 100% | Time: O(n) | Space: O(1) | 100-time-on-space-o1-by-pawelwar-xvpu | Complexity\n- Time complexity: O(n)\n- Space complexity: O(1)\n\n# Code\n\nclass Solution {\n public int[] findIndices(int[] nums, int indexDifference, int v | PawelWar | NORMAL | 2023-11-06T17:59:54.583692+00:00 | 2023-11-06T17:59:54.583722+00:00 | 6 | false | # Complexity\n- Time complexity: $$O(n)$$\n- Space complexity: $$O(1)$$\n\n# Code\n```\nclass Solution {\n public int[] findIndices(int[] nums, int indexDifference, int valueDifference) {\n int minValue = nums[0];\n int minIndex = 0;\n int maxValue = nums[0];\n int maxIndex = 0;\n\n ... | 0 | 0 | ['Java'] | 0 |
find-indices-with-index-and-value-difference-ii | [C++] Easy to Understand | c-easy-to-understand-by-samuel3shin-21to | Code\n\nclass Solution {\npublic:\n vector<int> findIndices(vector<int>& nums, int indexDifference, int valueDifference) {\n int N = nums.size();\n\n | Samuel3Shin | NORMAL | 2023-11-03T05:23:19.822858+00:00 | 2023-11-03T05:23:19.822886+00:00 | 4 | false | # Code\n```\nclass Solution {\npublic:\n vector<int> findIndices(vector<int>& nums, int indexDifference, int valueDifference) {\n int N = nums.size();\n\n vector<int> prefixMax(nums);\n vector<int> prefixMaxIdx(N, 0);\n for(int i=1; i<N; i++) {\n if(prefixMax[i-1] >= prefixMax[... | 0 | 0 | ['C++'] | 0 |
find-indices-with-index-and-value-difference-ii | Easy solution O(1)space, O(n)time | easy-solution-o1space-ontime-by-venkatpr-2hmo | 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 | venkatprabu007 | NORMAL | 2023-11-01T10:47:54.130839+00:00 | 2023-11-01T10:47:54.130862+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)$$ --... | 0 | 0 | ['Java'] | 0 |
find-indices-with-index-and-value-difference-ii | Simple c++ O(n) solution. | simple-c-on-solution-by-pathak9696-0v1r | \n# Approach\nFirstly initialise minindex , maxindex , j to be 0;\nAnd then started the loop from indexdifference.\nComparing the max value and min value from i | Pathak9696 | NORMAL | 2023-10-28T02:43:51.587746+00:00 | 2023-10-28T02:43:51.587766+00:00 | 4 | false | \n# Approach\nFirstly initialise minindex , maxindex , j to be 0;\nAnd then started the loop from indexdifference.\nComparing the max value and min value from index j if it is then update maxindex and minindex according to that.\nAfter that comparing done for valuedifference .....\n1->first with maxindex and i .**( "i"... | 0 | 0 | ['C++'] | 0 |
find-indices-with-index-and-value-difference-ii | Using Priority Queue / SortedList Solution. | using-priority-queue-sortedlist-solution-eh1e | Code\nC++ []\nclass Solution {\npublic:\n vector<int> findIndices(vector<int>& nums, int indexDifference, int valueDifference) {\n typedef pair<int, i | SEAQEN_KANI | NORMAL | 2023-10-27T13:23:09.455734+00:00 | 2023-10-27T13:23:09.455775+00:00 | 8 | false | # Code\n```C++ []\nclass Solution {\npublic:\n vector<int> findIndices(vector<int>& nums, int indexDifference, int valueDifference) {\n typedef pair<int, int> pii;\n auto cmp = [&](pii& a, pii& b) { return a.first > b.first; };\n priority_queue<pii, vector<pii>, decltype(cmp)> lo(cmp);\n ... | 0 | 0 | ['C++', 'Python3'] | 0 |
reverse-prefix-of-word | C++ (simple and clean: A diagram for Leetcoders :-)) | c-simple-and-clean-a-diagram-for-leetcod-noi8 | \n//Approach-1\nclass Solution {\npublic:\n string reversePrefix(string word, char ch) {\n for(int i = 0; i<word.length(); i++) {\n if(word | mazhar_mik | NORMAL | 2021-09-12T04:01:40.050221+00:00 | 2021-09-12T06:01:02.106393+00:00 | 6,476 | false | ```\n//Approach-1\nclass Solution {\npublic:\n string reversePrefix(string word, char ch) {\n for(int i = 0; i<word.length(); i++) {\n if(word[i] == ch) {\n reverse(begin(word), begin(word)+i+1);\n break;\n }\n }\n return word;\n }\n};\n```\... | 79 | 5 | [] | 17 |
reverse-prefix-of-word | 💯Faster✅💯 Lesser✅Detailed Explaination🎯Simple Approach🧠Step-by-Step Explanation✅Python🐍Java🍵C+ | faster-lesserdetailed-explainationsimple-5580 | \uD83D\uDE80 Hi, I\'m Mohammed Raziullah Ansari, and I\'m excited to share solution to this question with detailed explanation:\n\n# \uD83C\uDFAFProblem Explain | Mohammed_Raziullah_Ansari | NORMAL | 2024-05-01T01:13:42.871005+00:00 | 2024-05-01T01:16:29.145986+00:00 | 20,301 | false | # \uD83D\uDE80 Hi, I\'m [Mohammed Raziullah Ansari](https://leetcode.com/Mohammed_Raziullah_Ansari/), and I\'m excited to share solution to this question with detailed explanation:\n\n# \uD83C\uDFAFProblem Explaination: \nGiven a string `word` and a character `ch`, reverse the segment of `word` up to and including the ... | 66 | 9 | ['Two Pointers', 'String', 'C++', 'Java', 'Python3'] | 13 |
reverse-prefix-of-word | Find and reverse | find-and-reverse-by-votrubac-n0yg | C++\ncpp\nstring reversePrefix(string word, char ch) {\n auto p = word.find(ch);\n if (p != string::npos)\n reverse(begin(word), begin(word) + p + | votrubac | NORMAL | 2021-09-12T04:09:18.298213+00:00 | 2021-09-12T06:02:25.154464+00:00 | 4,410 | false | **C++**\n```cpp\nstring reversePrefix(string word, char ch) {\n auto p = word.find(ch);\n if (p != string::npos)\n reverse(begin(word), begin(word) + p + 1);\n return word;\n}\n```\n\nSince `string::npos` is defined as `-1`, the code above can be compressed:\n```cpp\nstring reversePrefix(string word, ch... | 36 | 0 | ['C'] | 9 |
reverse-prefix-of-word | 👏Beats 100.00% of users with Java🎉 || 💯2 Approaches || ⏩Fastest || ✅Easy & Well Explained🔥💥 | beats-10000-of-users-with-java-2-approac-6fgw | Intuition\nTo solve this problem, you need to find the index of the first occurrence of the character ch in the word. If it exists, reverse the segment of the w | Rutvik_Jasani | NORMAL | 2024-05-01T04:21:39.740695+00:00 | 2024-05-03T04:19:29.626001+00:00 | 6,784 | false | # Intuition\nTo solve this problem, you need to find the index of the first occurrence of the character ch in the word. If it exists, reverse the segment of the word from index 0 to that index. If not, do nothing. This involves searching for ch and manipulating the string accordingly.\n\n# I Think This Can Help You(For... | 32 | 0 | ['Two Pointers', 'String', 'Java'] | 9 |
reverse-prefix-of-word | String find/strchr & swaps||0ms beats 100% | string-findstrchr-swaps0ms-beats-100-by-nqs4n | Intuition\n Describe your first thoughts on how to solve this problem. \nA pratice for string.\nC string solution is rare which is also done. Python code is als | anwendeng | NORMAL | 2024-05-01T00:17:25.360491+00:00 | 2024-05-01T04:31:56.724099+00:00 | 5,804 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nA pratice for string.\nC string solution is rare which is also done. Python code is also given.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nUse find to find the location for `ch`. Then use successive swaps to rev... | 24 | 2 | ['String', 'C', 'C++', 'Python3'] | 8 |
reverse-prefix-of-word | JAVA | | Easy solution Beats 100% | java-easy-solution-beats-100-by-whj1117-y9x2 | ```\nclass Solution { \n public String reversePrefix(String word, char ch) {\n char[] c = word.toCharArray();\n int locate = 0;\n for (i | whj1117 | NORMAL | 2021-09-14T00:05:42.236195+00:00 | 2021-09-21T06:04:58.074578+00:00 | 4,470 | false | ```\nclass Solution { \n public String reversePrefix(String word, char ch) {\n char[] c = word.toCharArray();\n int locate = 0;\n for (int i = 0; i < word.length(); i++) { //first occurrence of ch\n if (ch == c[i]) {\n locate = i;\n break;\n }\... | 22 | 0 | ['String', 'Java'] | 9 |
reverse-prefix-of-word | Python Solution Beats 100 % time and 100 % space | python-solution-beats-100-time-and-100-s-uysa | \nclass Solution:\n def reversePrefix(self, word: str, ch: str) -> str:\n idx=word.find(ch) \n if idx:\n return word[:idx+1][::-1 | prajwal_vs | NORMAL | 2021-09-13T15:42:27.746356+00:00 | 2021-09-13T15:42:27.746403+00:00 | 3,179 | false | ```\nclass Solution:\n def reversePrefix(self, word: str, ch: str) -> str:\n idx=word.find(ch) \n if idx:\n return word[:idx+1][::-1]+ word[idx+1:]\n return word\n``` | 22 | 0 | ['String', 'Python'] | 9 |
reverse-prefix-of-word | 100% Faster || Easy to Understand || Shortest || C++ | Java | Python | JS. | 100-faster-easy-to-understand-shortest-c-2z8a | Intuition\nFind the first occurrence of the special character, then cleverly reverse the characters before it, leaving the rest untouched - a surgical strike of | gameboey | NORMAL | 2024-05-01T19:59:07.164924+00:00 | 2024-05-01T19:59:07.164969+00:00 | 1,000 | false | # Intuition\nFind the first occurrence of the special character, then cleverly reverse the characters before it, leaving the rest untouched - a surgical strike of rearrangement!\n\n# Approach\nCertainly, Nico Robin would break it down with numbered steps and a dry run example like this:\n\n"Dareshishishi... Let\'s go t... | 19 | 0 | ['String', 'C', 'C++', 'Java', 'Go', 'Python3', 'Scala', 'JavaScript', 'C#', 'Dart'] | 3 |
reverse-prefix-of-word | [Python 3] One-liner | Faster than 100% (Explained!) | python-3-one-liner-faster-than-100-expla-9cr1 | The idea is to slice the string upto and including ch, reverse that specific string segment, and concatenate the remaining string.\n\nExample:\n\n\nword = "abcd | TP0604 | NORMAL | 2021-09-12T09:26:46.584798+00:00 | 2021-09-24T19:40:55.170587+00:00 | 1,319 | false | The idea is to slice the string upto and including `ch`, reverse that specific string segment, and concatenate the remaining string.\n\nExample:\n\n```\nword = "abcdefd", ch = "d"\n\n#slice the string upto and including "d"\nword[:3 + 1] = "abcd"\n\n#reverse the string\nword[:3 + 1][::-1] = "dcba"\n\n#finally, add it t... | 13 | 0 | ['Python', 'Python3'] | 4 |
reverse-prefix-of-word | 🚀 💯 100% Beats 🔥 | | ✅both ✅green beats🧠 | | DSA solution in java | 100-beats-both-green-beats-dsa-solution-dgcu4 | # Intuition \n\n\n# Approach\n1. Find the index of the first occurrence of character ch in the string word.\n1. If the character ch is not found, return the o | Pintu008 | NORMAL | 2023-12-06T13:00:48.246551+00:00 | 2023-12-06T13:00:48.246570+00:00 | 329 | false | <!-- # Intuition -->\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. Find the index of the first occurrence of character ch in the string word.\n1. If the character ch is not found, return the original string.\n1. Create a StringBuilder to store the reversed segment.\n1. Iterate f... | 12 | 0 | ['String', 'Java'] | 3 |
reverse-prefix-of-word | 💯Fastest - 0 ms || ✅Easiest Explanation || Two Pointer 🔥 || 3️⃣ Lines of code || DryRun 🏋️♀️ | fastest-0-ms-easiest-explanation-two-poi-snby | Thanks for checking out my solution \u2764, You can view my profile here: TheCodeAlpha and check out other solutions too \uD83D\uDC4D\n\n# Approach 1 : Two Poin | TheCodeAlpha | NORMAL | 2024-05-01T07:02:53.584474+00:00 | 2024-05-01T18:19:31.763383+00:00 | 668 | false | #### Thanks for checking out my solution \u2764, You can view my profile here: [TheCodeAlpha](https://leetcode.com/u/TheCodeAlpha/) and check out other solutions too \uD83D\uDC4D\n\n# Approach 1 : Two Pointer\n\n# Intuition\n\n- Pehla khayaal jo mujhe aaya (Vo uska nahi tha), vo ye tha ki apne ko chahiye diye huyi char... | 11 | 1 | ['Two Pointers', 'String', 'C++', 'Java', 'Python3'] | 1 |
reverse-prefix-of-word | C++ 2-line solution (O(N) time & O(1) space) | c-2-line-solution-on-time-o1-space-by-mi-u6ak | \nclass Solution {\npublic:\n string reversePrefix(string& word, const char& ch) {\n reverse(word.begin(), word.begin() + word.find(ch) + 1);\n | minato_yukina | NORMAL | 2021-09-12T05:35:51.041093+00:00 | 2021-09-12T05:35:51.041134+00:00 | 939 | false | ```\nclass Solution {\npublic:\n string reversePrefix(string& word, const char& ch) {\n reverse(word.begin(), word.begin() + word.find(ch) + 1);\n return word;\n }\n};\n``` | 11 | 0 | [] | 3 |
reverse-prefix-of-word | ✅Detailed Explaination||Step-by-Step Explanation✅Python🐍Java🍵C+ | detailed-explainationstep-by-step-explan-damm | \n\n# Code\n# C++\n\nclass Solution {\npublic:\n string reversePrefix(string word, char ch) {\n string ans;\n\n // Find the index of the charac | sujalgupta09 | NORMAL | 2024-05-01T04:22:41.705943+00:00 | 2024-05-01T04:22:41.705979+00:00 | 2,202 | false | \n\n# Code\n# C++\n```\nclass Solution {\npublic:\n string reversePrefix(string word, char ch) {\n string ans;\n\n // Find the index of the character \'ch\' in the word\n int ind = 0;\n for(int i = 0; i < word.length(); i++){\n if(word[i] == ch){\n ind = i;\n ... | 10 | 0 | ['C++'] | 2 |
reverse-prefix-of-word | 🗓️ Daily LeetCoding Challenge Day 133|| 🔥 JAVA SOL | daily-leetcoding-challenge-day-133-java-emch3 | Code\n\nclass Solution {\n public String reversePrefix(String word, char ch) {\n int j = word.indexOf(ch);\n if (j != -1) {\n return | DoaaOsamaK | NORMAL | 2024-05-01T03:37:45.989920+00:00 | 2024-05-01T03:37:45.989960+00:00 | 1,303 | false | # Code\n```\nclass Solution {\n public String reversePrefix(String word, char ch) {\n int j = word.indexOf(ch);\n if (j != -1) {\n return new StringBuilder(word.substring(0, j + 1)).reverse().toString() + word.substring(j + 1);\n }\n return word;\n }\n}\n``` | 10 | 0 | ['Java'] | 3 |
reverse-prefix-of-word | Ruby Solution | like plx | ruby-solution-like-plx-by-bornfundeath-cle9 | \n# Code\n\n# @param {String} word\n# @param {Character} ch\n# @return {String}\ndef reverse_prefix(word, ch)\n dest_index = word.index(ch).to_i + ch.length\ | bornfundeath | NORMAL | 2023-11-19T05:25:14.482188+00:00 | 2023-11-19T05:25:14.482211+00:00 | 197 | false | \n# Code\n```\n# @param {String} word\n# @param {Character} ch\n# @return {String}\ndef reverse_prefix(word, ch)\n dest_index = word.index(ch).to_i + ch.length\n reverse_word = word[0...dest_index].reverse\n new_word = word[dest_index...word.length]\n return reverse_word + new_word\nend\n``` | 10 | 1 | ['Ruby'] | 1 |
reverse-prefix-of-word | Two Solutions. Two Pointers( 93%/97% ) | two-solutions-two-pointers-9397-by-kubat-2xcu | \n/**\n * @param {string} word\n * @param {character} ch\n * @return {string}\n */\nvar reversePrefix = function(word, ch) {\n // #1\n let chIndex = word. | kubatabdrakhmanov | NORMAL | 2022-10-30T11:43:47.559081+00:00 | 2022-10-30T11:43:47.559115+00:00 | 1,466 | false | ```\n/**\n * @param {string} word\n * @param {character} ch\n * @return {string}\n */\nvar reversePrefix = function(word, ch) {\n // #1\n let chIndex = word.indexOf(ch)\n if(chIndex < 0) return word\n \n let result = \'\'\n \n for(let i = chIndex; i >= 0; i--){\n result += word[i]\n }\n ... | 10 | 0 | ['JavaScript'] | 3 |
reverse-prefix-of-word | 🔥 6 lines of simple code beat 100% users 🚀 fully explained ✅ || Easy to understand 👍 | 6-lines-of-simple-code-beat-100-users-fu-ndnl | Intuition\nPython, Python3 and C++ :\n1. Iterate through the characters of the string \'word\' until you find the first occurrence of the specified character \' | siddharth-kiet | NORMAL | 2024-05-01T07:04:52.560799+00:00 | 2024-05-01T07:05:06.279420+00:00 | 1,652 | false | # Intuition\n**Python, Python3 and C++ :**\n1. Iterate through the characters of the string **\'word\'** until you find the first occurrence of the specified character **\'ch\'**.\n2. Once found, store the index of the occurrence in **\'c\'**.\n3. Extract the substring from the beginning of the **\'word\'** string up t... | 9 | 0 | ['String', 'Python', 'C++', 'Python3'] | 2 |
reverse-prefix-of-word | Python 3 || 3 lines, index and string slices || T/S: 91% / 99% | python-3-3-lines-index-and-string-slices-4ti0 | \nclass Solution:\n def reversePrefix(self, word: str, ch: str) -> str:\n \n if ch not in word: return word\n\n idx = word.index(ch)\n | Spaulding_ | NORMAL | 2024-05-01T00:46:47.789834+00:00 | 2024-06-11T21:34:55.626215+00:00 | 501 | false | ```\nclass Solution:\n def reversePrefix(self, word: str, ch: str) -> str:\n \n if ch not in word: return word\n\n idx = word.index(ch)\n return word[:idx+1][::-1]+ word[idx+1:]\n```\n[https://leetcode.com/problems/reverse-prefix-of-word/submissions/607834040/](https://leetcode.com/problems/r... | 9 | 0 | ['Python3'] | 2 |
reverse-prefix-of-word | two methods || python || easy to understand | two-methods-python-easy-to-understand-by-b9lt | \n\n# Code\n\nclass Solution:\n def reversePrefix(self, word: str, ch: str) -> str:\n """\n #method 1:\n for i in range(len(word)):\n | Kairanishanth | NORMAL | 2022-12-15T16:38:17.992719+00:00 | 2022-12-15T16:38:17.992757+00:00 | 946 | false | \n\n# Code\n```\nclass Solution:\n def reversePrefix(self, word: str, ch: str) -> str:\n """\n #method 1:\n for i in range(len(word)):\n if word[i]==ch:\n return word[:i+1][::-1]+word[i+1:]\n return word"""\n #method 2:\n l=0\n r=word.find(ch... | 9 | 0 | ['Python3'] | 2 |
reverse-prefix-of-word | [JAVA] | indexOf() | O(N) Time | 100% Optimal & Faster Solution | java-indexof-on-time-100-optimal-faster-q6e5z | \nclass Solution {\n public String reversePrefix(String word, char ch) {\n int index=word.indexOf(ch);\n if(index!=-1)\n return reverse( | kanojiyakaran | NORMAL | 2021-09-15T16:06:49.770274+00:00 | 2021-09-15T16:06:49.770321+00:00 | 1,259 | false | ```\nclass Solution {\n public String reversePrefix(String word, char ch) {\n int index=word.indexOf(ch);\n if(index!=-1)\n return reverse(index,index+1,word); \n else \n return word;\n }\n \n public String reverse(int i,int j,String word){\n StringBuilder sb=new S... | 9 | 0 | ['Java'] | 3 |
reverse-prefix-of-word | C++ || 3 Liner Solution || Easy-to-understand | c-3-liner-solution-easy-to-understand-by-2xcb | class Solution {\npublic:\n string reversePrefix(string word, char ch) {\n int pos=word.find(ch);\n reverse(word.begin(),word.begin()+pos+1);\n | venom-xd | NORMAL | 2022-03-02T13:23:09.697192+00:00 | 2022-03-02T13:23:09.697236+00:00 | 524 | false | class Solution {\npublic:\n string reversePrefix(string word, char ch) {\n int pos=word.find(ch);\n reverse(word.begin(),word.begin()+pos+1);\n return word;\n }\n};\n | 8 | 1 | ['String', 'C'] | 1 |
reverse-prefix-of-word | Java 100% fast,Easy | java-100-fasteasy-by-aniketalok863-37w6 | ```\n public String reversePrefix(String word, char ch) {\n StringBuilder sb=new StringBuilder();\n int index=word.indexOf(ch);\n sb.append | aniketalok863 | NORMAL | 2021-10-02T05:31:35.265731+00:00 | 2021-10-02T05:31:35.265763+00:00 | 794 | false | ```\n public String reversePrefix(String word, char ch) {\n StringBuilder sb=new StringBuilder();\n int index=word.indexOf(ch);\n sb.append(word.substring(0,index+1));\n sb.reverse();\n sb.append(word.substring(index+1));\n return sb.toString();\n \n } | 8 | 1 | ['Java'] | 2 |
reverse-prefix-of-word | 🔥 100% Faster | Reverse Prefix Using Stack | Optimized C++ Solution 🚀 | 100-faster-reverse-prefix-using-stack-op-8pt2 | IntuitionUse a stack to store characters up to the first occurrence of ch, then pop from the stack to reverse the prefix in place.Approach
Find the first occurr | FarhanTalkal | NORMAL | 2025-03-02T14:48:28.278519+00:00 | 2025-03-02T14:48:28.278519+00:00 | 301 | false | # Intuition
Use a stack to store characters up to the first occurrence of ch, then pop from the stack to reverse the prefix in place.
# Approach
1. **Find the first occurrence of `ch`** in `word` while pushing characters onto a stack.
2. If `ch` is not found, return `word` as is.
3. **Pop characters from the stack... | 7 | 0 | ['String', 'Stack', 'C++'] | 0 |
reverse-prefix-of-word | Easy Python Solution (28ms) | Faster than 93% | easy-python-solution-28ms-faster-than-93-2xgz | Easy Python Solution (28ms) | Faster than 93%\nRuntime: 28 ms, faster than 93% of Python3 online submissions for Reverse Prefix of Word.\nMemory Usage: 14.3 MB\ | the_sky_high | NORMAL | 2021-09-19T10:17:39.961987+00:00 | 2021-09-19T10:18:40.538842+00:00 | 1,281 | false | # Easy Python Solution (28ms) | Faster than 93%\n**Runtime: 28 ms, faster than 93% of Python3 online submissions for Reverse Prefix of Word.\nMemory Usage: 14.3 MB**\n\n```\nclass Solution:\n def reversePrefix(self, word: str, ch: str) -> str:\n try:\n ix = word.index(ch)\n return word[:... | 7 | 1 | ['String', 'Python', 'Python3'] | 3 |
reverse-prefix-of-word | Simple Golang Solution | simple-golang-solution-by-nathannaveen-nx4w | The idea of this solution is:\n\n We reverse the first i letters of word and store it as s.\n Then when word[i] (letter) equals ch we can return s + word[i + 1: | nathannaveen | NORMAL | 2021-09-13T15:42:40.311510+00:00 | 2021-09-19T13:12:29.238912+00:00 | 216 | false | The idea of this solution is:\n\n* We reverse the first `i` letters of `word` and store it as `s`.\n* Then when `word[i]` (`letter`) equals `ch` we can return `s + word[i + 1:]` (The reversed string up to`i`, and then the remaining of `word`)\n\n```\nfunc reversePrefix(word string, ch byte) string {\n s := ""\n \... | 7 | 0 | ['Go'] | 1 |
reverse-prefix-of-word | Easy to Understand Solution || C++ || Reverse | easy-to-understand-solution-c-reverse-by-j088 | Idea is simple, find the position of ch in word. If not found return -1. \n\nOtherwise, reverse the word starting from beginning of word till position of ch+1. | i_quasar | NORMAL | 2021-09-12T04:03:35.243919+00:00 | 2021-09-12T04:10:26.712030+00:00 | 551 | false | **Idea** is simple, find the position of `ch` in word. If not found return -1. \n\nOtherwise, reverse the word starting from beginning of word till position of ch+1. \n\n\t\treverse(word.begin(), word.begin() + pos + 1);\n\n# Code : \n```\n string reversePrefix(string word, char ch) {\n \n\tint pos = -1;\n\tfor(... | 7 | 0 | ['String', 'C'] | 0 |
reverse-prefix-of-word | EASY JAVA SOLUTION for BEGINNERS [1ms] | easy-java-solution-for-beginners-1ms-by-8689d | Approach\n1. Initialize Variables:\n - Create int ind to store the index of ch.\n - Initialize StringBuilder str for the resulting string.\n\n2. Find the In | RajarshiMitra | NORMAL | 2024-05-26T06:58:21.780641+00:00 | 2024-06-16T06:46:33.652885+00:00 | 74 | false | # Approach\n1. **Initialize Variables**:\n - Create `int ind` to store the index of `ch`.\n - Initialize `StringBuilder str` for the resulting string.\n\n2. **Find the Index of `ch`**:\n - Iterate through `word` to find the first occurrence of `ch`.\n - Store the index in `ind` and break the loop.\n\n3. **Rever... | 6 | 0 | ['Java'] | 0 |
reverse-prefix-of-word | C++ and C# very easy solution. | c-and-c-very-easy-solution-by-aloneguy-co71 | \n\n\nC# []\npublic class Solution {\n public string ReversePrefix(string word, char ch) {\n char[] a = word.ToCharArray();\n for(int i = 0; i < | aloneguy | NORMAL | 2023-04-12T01:22:26.370610+00:00 | 2023-04-12T01:22:26.370650+00:00 | 1,203 | false | \n\n\n```C# []\npublic class Solution {\n publi... | 6 | 0 | ['String', 'C++', 'C#'] | 3 |
reverse-prefix-of-word | Simple Javascript solution with 87% faster | simple-javascript-solution-with-87-faste-bwjh | Runtime: 64 ms, faster than 87.29% of JavaScript online submissions for Reverse Prefix of Word.\n\nconst reversePrefix = (word, ch) => {\n const indexCh = word | khoabt94 | NORMAL | 2022-07-14T08:31:42.493415+00:00 | 2022-07-14T08:31:42.493449+00:00 | 571 | false | Runtime: 64 ms, faster than 87.29% of JavaScript online submissions for Reverse Prefix of Word.\n\nconst reversePrefix = (word, ch) => {\n const indexCh = word.indexOf(ch);\n if (indexCh === -1) return word;\n\n const sliceString = word\n .slice(0, indexCh + 1)\n .split("")\n .reverse()\n .join("");\n\n ... | 6 | 0 | ['JavaScript'] | 1 |
reverse-prefix-of-word | 💯JAVA Solution Explained in HINDI | java-solution-explained-in-hindi-by-the_-ptgu | https://youtu.be/TpdXeHsMmLk\n\nFor explanation, please watch the above video and do like, share and subscribe the channel. \u2764\uFE0F Also, please do upvote | The_elite | NORMAL | 2024-05-01T13:55:01.561638+00:00 | 2024-05-01T13:55:01.561673+00:00 | 345 | false | https://youtu.be/TpdXeHsMmLk\n\nFor explanation, please watch the above video and do like, share and subscribe the channel. \u2764\uFE0F Also, please do upvote the solution if you liked it.\n\n# Subscribe:- [ReelCoding](https://www.youtube.com/@reelcoding?sub_confirmation=1)\n\nSubscribe Goal:- 400\nCurrent Subscriber:... | 5 | 0 | ['Java'] | 1 |
reverse-prefix-of-word | ✅ One Line Solution | one-line-solution-by-mikposp-viqw | (Disclaimer: this is not an example to follow in a real project - it is written for fun and training mostly)\n\n# Code #1\nTime complexity: O(n). Space complexi | MikPosp | NORMAL | 2024-05-01T08:08:42.198889+00:00 | 2024-05-01T08:08:42.198912+00:00 | 451 | false | (Disclaimer: this is not an example to follow in a real project - it is written for fun and training mostly)\n\n# Code #1\nTime complexity: $$O(n)$$. Space complexity: $$O(n)$$.\n```\nclass Solution:\n def reversePrefix(self, w: str, c: str) -> str:\n return w[:(q:=w.find(c)+1)][::-1]+w[q:]\n```\n\n# Code #2\... | 5 | 1 | ['String', 'Python', 'Python3'] | 1 |
reverse-prefix-of-word | ✅Easy✨||C++|| Beats 100% || With Explanation || | easyc-beats-100-with-explanation-by-olak-ry59 | Intuition\n Describe your first thoughts on how to solve this problem. \nAll we need to do is to find the position of the first occurence of the target char.\nT | olakade33 | NORMAL | 2024-05-01T05:52:04.542532+00:00 | 2024-05-01T05:52:04.542555+00:00 | 1,433 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nAll we need to do is to find the position of the first occurence of the target char.\nThen we need to reverse this part of the string.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. In the given string, find the ... | 5 | 0 | ['C++'] | 2 |
reverse-prefix-of-word | ✅ 🔥Java | Short solution | Easy understanding ✅ 🔥 | java-short-solution-easy-understanding-b-59up | Given constraints are simple, so better to keep the answer as well simple in 3 lines.\n\n\t\t Find the index of the given char\n\t\t Reverse till that index\n\t | Surendaar | NORMAL | 2024-05-01T03:15:25.843081+00:00 | 2024-05-01T03:25:06.606038+00:00 | 1,095 | false | Given constraints are simple, so better to keep the answer as well simple in 3 lines.\n\n\t\t* Find the index of the given char\n\t\t* Reverse till that index\n\t\t* Return the substring of reversed charecter and the remaining char in original string.\n\n```\n public String reversePrefix(String word, char ch) {\n ... | 5 | 0 | ['Java'] | 2 |
reverse-prefix-of-word | ✅ Beats 100% | 3 lines only ⚡| built_in methods are usefull 😉 | beats-100-3-lines-only-built_in-methods-xjejl | \n# Intuition\n Describe your first thoughts on how to solve this problem. \n All we need to do is to find the position of the first occurence of the target cha | abdelazizSalah | NORMAL | 2024-05-01T00:16:21.151853+00:00 | 2024-05-01T00:19:54.099595+00:00 | 1,238 | false | \n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n* All we need to do is to find the position of the first occurence of the target char. \n* Then we need to reverse this pa... | 5 | 1 | ['Two Pointers', 'String', 'C++'] | 2 |
reverse-prefix-of-word | Java | Faster than 100% Solution | java-faster-than-100-solution-by-nknidhi-kudf | Do vote up if you like it :)\n\nclass Solution {\n public String reversePrefix(String word, char ch) {\n int len = word.length();\n for(int i = | nknidhi321 | NORMAL | 2021-10-02T20:42:57.684611+00:00 | 2021-10-02T20:42:57.684643+00:00 | 488 | false | **Do vote up if you like it :)**\n```\nclass Solution {\n public String reversePrefix(String word, char ch) {\n int len = word.length();\n for(int i = 0; i < len; i++) {\n if(word.charAt(i) == ch) {\n String reversedString = reverse(word.substring(0, i+1));\n re... | 5 | 0 | [] | 2 |
reverse-prefix-of-word | C++ Easy Solution | c-easy-solution-by-parth_chovatiya-i6pw | Just find the first occurence and reverse string till that occurence.\n\nclass Solution {\npublic:\n string reversePrefix(string word, char ch) {\n st | parth_chovatiya | NORMAL | 2021-09-12T04:11:45.553887+00:00 | 2021-09-13T05:28:38.933250+00:00 | 375 | false | Just find the first occurence and reverse string till that occurence.\n```\nclass Solution {\npublic:\n string reversePrefix(string word, char ch) {\n string ans = "";\n int tr = true;\n for(auto w : word){\n ans.push_back(w);\n if(tr && w == ch){\n tr=false;... | 5 | 0 | ['C'] | 2 |
reverse-prefix-of-word | Java One Liner | java-one-liner-by-vikrant_pc-uinx | \npublic String reversePrefix(String word, char ch) {\n\treturn new StringBuilder(word.substring(0, word.indexOf(ch) + 1)).reverse().toString() + word.substring | vikrant_pc | NORMAL | 2021-09-12T04:03:21.609107+00:00 | 2021-09-12T04:03:21.609150+00:00 | 408 | false | ```\npublic String reversePrefix(String word, char ch) {\n\treturn new StringBuilder(word.substring(0, word.indexOf(ch) + 1)).reverse().toString() + word.substring(word.indexOf(ch) + 1);\n}\n``` | 5 | 3 | [] | 1 |
reverse-prefix-of-word | Beats 100.00% of users with Java🎉 || 0 MS || ⏩Fastest || Simple | beats-10000-of-users-with-java-0-ms-fast-nzg3 | Code | yogaasri_t | NORMAL | 2025-02-16T08:46:04.460538+00:00 | 2025-02-16T08:46:04.460538+00:00 | 413 | false |
# Code
```java []
class Solution {
public String reversePrefix(String word, char ch) {
int index = word.indexOf(ch);
return index >= 0 ?
new StringBuilder(word.substring(0,index+1))
.reverse()
.append(word.substring(index+1,word.length()))
... | 4 | 0 | ['String', 'Java'] | 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.