1. Problem Statement (Simple Explanation): You are given two integers: dividend divisor (non-zero) You must compute: Subject to: You cannot use : multiplication (*) division (/) modulo (%) You must handle 32-bit signed integer range : [-2 31 ,2 31 -1]=[-2147483648,2147483647] If the quotient is strictly greater than 2 31 - 1, return 2 31 - 1. If the quotient is strictly less than -2 31 , return -2 31 . Truncation toward zero means: 8 / 3 = 2.66... → 2 -8 / 3 = -2.66... → -2 2. Examples: Example 1: Input: dividend = 10, divisor = 3 Exact division: 10 / 3 ≈ 3.3333 → truncated toward zero → 3. Output: 3 Example 2: Input: dividend = 7, divisor = -3 Exact division: 7 / -3 ≈ -2.3333 → truncated toward zero → -2. Output: -2 Constraints: -2 31 <= dividend, divisor <= 2 31 -1 divisor != 0 3. Approach 1 – Naive Repeated Subtraction (Too Slow): Conceptually: Repeatedly ...
1. Problem Statement (Simple Explanation): You are given two strings: haystack: the main string needle: the substring to search for Return: The index of the first occurrence of needle in haystack. If needle is not part of haystack, return -1. Indexing is 0-based . 2. Examples: Example 1: Input: haystack = "sadbutsad" needle = "sad" Occurrences of "sad": At index 0: "sad"butsad At index 6: sadb ut"sad" First occurrence is at index 0. Output: 0 Example 2: Input: haystack = "leetcode" needle = "leeto" "leeto" does not appear in "leetcode". Output: -1 Constraints: 1 <= haystack.length, needle.length <= 10 4 Both strings consist of only lowercase English letters. 3. Approach – Simple Sliding Window (Brute Force, O(n·m)): Given constraints up to 10 4 , a straightforward O(n·m) solution is acceptable. Let: n = len(haystack) m = len(needle) We che...