├── .DS_Store ├── .gitignore ├── All Other Program └── Q3.java ├── All Other Programs ├── FizzBuzz.js ├── IntegerToRoman.js ├── Machine Learning.ipynb ├── Navbar.js ├── PlayerMovementTutorial.cs ├── README.md ├── ReverseLinkedList.js ├── ageCalculator.js ├── binarySearchTree.js ├── calendar.js ├── compareIntegers.js ├── date.html ├── fibonacciSequence.js ├── find-the-duplicate-number ├── greatestCommonDivisor.js ├── index.js ├── numberEncoder.js ├── primeNumbers.js ├── queueImplementation.js ├── shell_Script_tochangeformat.sh ├── signOfProducts.js ├── stackImplementation.js └── tipCalculator.js ├── C Programs ├── Bubble Sorting an Array using pointers.c ├── CaesarCipher.c ├── Calculate Compound Interest.c ├── Complex No Passing Structure to Function with pointer.c ├── Convert Binary Number to Decimal.c ├── Dequeque.c ├── DistanceToCheckpoint.cs ├── Fibonacci.c ├── Make a Rectangle.c ├── NVL_TREE_CHECK.c ├── README.md ├── Shortest_Distance_of_Network.c ├── Spiral Matrix.c ├── SumTwo.c ├── Swap.c ├── armstrong.c ├── c.c ├── do.c ├── factorial.c ├── lab_sheet.c ├── lab_sheet_1.c ├── lab_sheet_2.c ├── lab_sheet_3.c ├── new.c ├── populatearray.c ├── rollerCoaster.c ├── strings.c ├── unionofarray.c └── xox game.c ├── C# Programs ├── Client │ ├── .vscode │ │ ├── launch.json │ │ └── tasks.json │ ├── Client.csproj │ └── Program.cs └── Server │ ├── .vscode │ ├── launch.json │ └── tasks.json │ ├── Program.cs │ └── Server.csproj ├── C++ Programs ├── 1281-subtract-the-product-and-sum-of-digits-of-an-integer │ ├── 1281-subtract-the-product-and-sum-of-digits-of-an-integer.cpp │ ├── NOTES.md │ └── README.md ├── 135-candy │ ├── README.md │ └── candy.cpp ├── 1480-running-sum-of-1d-array │ ├── 1480-running-sum-of-1d-array.cpp │ ├── NOTES.md │ └── README.md ├── 1491-average-salary-excluding-the-minimum-and-maximum-salary │ ├── 1491-average-salary-excluding-the-minimum-and-maximum-salary.cpp │ ├── NOTES.md │ └── README.md ├── 1523-count-odd-numbers-in-an-interval-range │ ├── 1523-count-odd-numbers-in-an-interval-range.cpp │ ├── NOTES.md │ └── README.md ├── 1752-check-if-array-is-sorted-and-rotated │ ├── 1752-check-if-array-is-sorted-and-rotated.cpp │ ├── NOTES.md │ └── README.md ├── 1757-recyclable-and-low-fat-products │ ├── 1757-recyclable-and-low-fat-products.sql │ ├── NOTES.md │ └── README.md ├── 26-remove-duplicates-from-sorted-array ├── 344-reverse-string │ ├── 344-reverse-string.cpp │ ├── NOTES.md │ └── README.md ├── 509-fibonacci-number │ ├── 509-fibonacci-number.cpp │ ├── NOTES.md │ └── README.md ├── 557-reverse-words-in-a-string-iii │ ├── 557-reverse-words-in-a-string-iii.cpp │ ├── NOTES.md │ └── README.md ├── 567-permutation-in-string │ ├── 567-permutation-in-string.cpp │ ├── NOTES.md │ └── README.md ├── 704-binary-search │ ├── 704-binary-search.cpp │ ├── NOTES.md │ └── README.md ├── 724-find-pivot-index │ ├── 724-find-pivot-index.cpp │ ├── NOTES.md │ └── README.md ├── 852-peak-index-in-a-mountain-array │ ├── 852-peak-index-in-a-mountain-array.cpp │ ├── NOTES.md │ └── README.md ├── BellmanFordAlgorithm.cpp ├── Codeforces Problems │ ├── CommentoryBox.cpp │ ├── Friends meeting.cpp │ └── love triangle.cpp ├── DijkstraAlgorithm.cpp ├── FloydWarshallAlgorithm.cpp ├── Greedy │ ├── 134. Gas Station.cpp │ ├── 135-Candy.cpp │ ├── 1561. Max_Coins_You_Can_Get.cpp │ └── 1642. Furthest_Building_You_Can_Reach.cpp ├── Heap_Sort.cpp ├── KosarajuAlgorithm.cpp ├── LargestContiguousArraySum.cpp ├── PascalTriangle.cpp ├── Quick-sort.cpp ├── README.md ├── String-is-palindrome-or-not ├── TravellingSalseman.cpp ├── ans.cpp ├── binary_search.cpp ├── connected_components_undirected_graph.cpp ├── intersectionofLinkedLists.cpp ├── linear_search.cpp ├── mergeSort.cpp ├── palindrome.cpp ├── reverseLinkedList.cpp ├── runTimePolymorphism.cpp ├── size └── twosum.cpp ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Clojure Programs ├── .DS_Store └── Webshop │ ├── .DS_Store │ ├── Dockerfile │ ├── LICENCSE │ ├── README.md │ ├── docker-compose.yml │ ├── img │ └── demo.png │ ├── metro.iml │ ├── project.clj │ ├── resources │ ├── .DS_Store │ └── public │ │ ├── .DS_Store │ │ ├── css │ │ ├── bootstrap.min.css │ │ ├── bootstrap.min.css.map │ │ ├── cat.css │ │ └── custom.css │ │ └── img │ │ ├── products │ │ ├── bacon.jpg │ │ ├── crinklefries.jpg │ │ ├── fryingfat.jpg │ │ ├── garlic.jpg │ │ ├── icecream.jpg │ │ ├── oliveoil.jpg │ │ ├── shrimps.jpg │ │ ├── steakhousefries.jpg │ │ ├── sweetpotatoefries.jpg │ │ └── tortilla.jpg │ │ └── shopping-cart.svg │ ├── src │ └── metro │ │ ├── components │ │ ├── db │ │ │ ├── articles.clj │ │ │ └── postgres.clj │ │ ├── server │ │ │ ├── pedestal.clj │ │ │ └── routes.clj │ │ └── web │ │ │ ├── api.clj │ │ │ ├── blocks.clj │ │ │ ├── health.clj │ │ │ └── views.clj │ │ └── system.clj │ ├── target │ ├── .DS_Store │ ├── default+repl │ │ ├── .DS_Store │ │ ├── classes │ │ │ └── META-INF │ │ │ │ └── maven │ │ │ │ └── metro │ │ │ │ └── metro │ │ │ │ └── pom.properties │ │ ├── repl-port │ │ └── stale │ │ │ └── leiningen.core.classpath.extract-native-dependencies │ ├── default+test+test │ │ ├── .DS_Store │ │ ├── classes │ │ │ └── META-INF │ │ │ │ └── maven │ │ │ │ └── metro │ │ │ │ └── metro │ │ │ │ └── pom.properties │ │ └── stale │ │ │ └── leiningen.core.classpath.extract-native-dependencies │ └── default │ │ ├── .DS_Store │ │ ├── classes │ │ └── META-INF │ │ │ └── maven │ │ │ └── metro │ │ │ └── metro │ │ │ └── pom.properties │ │ └── stale │ │ └── leiningen.core.classpath.extract-native-dependencies │ ├── test │ ├── .DS_Store │ └── metro │ │ ├── .DS_Store │ │ ├── db │ │ └── articles_test.clj │ │ ├── system_test.clj │ │ └── web │ │ └── routes_test.clj │ └── testing.sqlite3 ├── Java Programs ├── CheckForElement.java ├── CheckSortedArray.java ├── Combinations.java ├── CountDigits.java ├── CountFreq.java ├── Factorial.java ├── Factors ├── FirstOccur.java ├── GetIndices.java ├── HeapSort.java ├── KadaneAlgo.java ├── LastOccur.java ├── LeftRotate.java ├── MinMaxInTheArray.java ├── MultiplyMatrices ├── NumberGuessingGame.java ├── Plaindrome.java ├── PowerCalculate.java ├── PowerSet.java ├── PrintNnumber.java ├── README.md ├── RainWaterTrapping.java ├── ReverseRecursion ├── SecondLargest.java ├── SecondLargestElement.java ├── SlidingWindow.java ├── SortStrings ├── SumOfArray.java ├── SumOfNaturalNumbers.java ├── TowerOfHanoi.java ├── TwoPointerAlgo.java ├── WriteFileTemplate.java ├── cShakerSort.java ├── check.java ├── checkDuplicate.java ├── intsum.java ├── jdbc.java ├── jdbcconn.java ├── min.java ├── odd.java ├── rec.java ├── small_large.java ├── sumnavg.java ├── validSquare └── value2.java ├── Java Script Programs ├── BMIcalculator.js ├── Readme.md └── simple-calculation.js ├── LICENSE ├── Python Programs ├── Armstrong.py ├── Automated_Text_on_Image_Using_PIL.py ├── Bubblesort.py ├── Counting_Objects_in_image.py ├── Drawing-Car-Using-Python.py ├── Electricitybill.py ├── Fahrenheit_to_Celsius.py ├── Generate-QR-Code.py ├── Image-to-sketch.py ├── IndianFlag.py ├── LongestPalindromicSubstring.py ├── Minimum Elements to Add to Form a Given Sum.py ├── README.md ├── Unimodal.py ├── binary_search.py ├── binary_tree_inorder_traversal. py ├── binary_tree_preorder_traversal. py ├── binarysearch.py ├── bins_kclosestelements.py ├── calc.py ├── calendar.py ├── count-negatives-in-matrix.py ├── db_access.py ├── electric.py ├── first.py ├── fourth.py ├── image processing with opencv.ipynb ├── longestValidParentheses.py ├── main.py ├── multilevelInheritance.py ├── number_guessing_game.py ├── palindrome.py ├── portscanner.py ├── powerOf2.py ├── printSubArrays.py ├── quiz_game.py ├── second.py ├── send_email.py ├── stone_paper_scissors_game.py ├── stuckYourPC.py ├── third.py └── update_tuple.py ├── README.md ├── Sprig Programs ├── Maze Runner.js ├── Paint_IT.js ├── README.md ├── Shooter JS Game.js ├── Trash IT!.js ├── Trash_IT.js ├── Virtual_Machine.js └── love_lock.js ├── area ├── climbing stairs.cpp └── temp.py /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StuntStorm/Program-Collection/d22c57f946d1c3887d426b30d222a3b38ac839d7/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .DS_Store 3 | -------------------------------------------------------------------------------- /All Other Program/Q3.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | 4 | class Q3 5 | { 6 | public static void main(String args[]) 7 | { 8 | int a,b,c; 9 | Scanner sc = new Scanner(System.in); 10 | System.out.println("Enter the First Number : "); 11 | a = sc.nextInt(); 12 | System.out.println("Enter the Second Number : "); 13 | b = sc.nextInt(); 14 | System.out.println("Enter the Third Number : "); 15 | c = sc.nextInt(); 16 | if(a>b && a>c) 17 | { 18 | System.out.println(a+" is the Biggest Number"); 19 | } 20 | else if(b>a && b>c) 21 | { 22 | System.out.println(b+" is the Biggest Number"); 23 | } 24 | else 25 | { 26 | System.out.println(c+" is the Biggest Number"); 27 | } 28 | 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /All Other Programs/FizzBuzz.js: -------------------------------------------------------------------------------- 1 | function fizzy(n) { 2 | let answer = []; 3 | for (let i = 1; i <= n; i++) { 4 | if (i % 5 == 0 && i % 3 == 0) { 5 | answer.push("FizzBuzz"); 6 | } else if (i % 5 == 0) { 7 | answer.push("Buzz"); 8 | } else if (i % 3 == 0) { 9 | answer.push("Fizz"); 10 | } else { 11 | answer.push(i.toString()); 12 | } 13 | } 14 | return answer; 15 | } 16 | console.log(fizzy(15)); 17 | -------------------------------------------------------------------------------- /All Other Programs/IntegerToRoman.js: -------------------------------------------------------------------------------- 1 | function intToRoman(num) { 2 | let result = ""; 3 | while (num) { 4 | if (num >= 1000) { 5 | result += "M"; 6 | num -= 1000; 7 | } else if (num >= 500) { 8 | if (num >= 900) { 9 | result += "CM"; 10 | num -= 900; 11 | } else { 12 | result += "D"; 13 | num -= 500; 14 | } 15 | } else if (num >= 100) { 16 | if (num >= 400) { 17 | result += "CD"; 18 | num -= 400; 19 | } else { 20 | result += "C"; 21 | num -= 100; 22 | } 23 | } else if (num >= 50) { 24 | if (num >= 90) { 25 | result += "XC"; 26 | num -= 90; 27 | } else { 28 | result += "L"; 29 | num -= 50; 30 | } 31 | } else if (num >= 10) { 32 | if (num >= 40) { 33 | result += "XL"; 34 | num -= 40; 35 | } else { 36 | result += "X"; 37 | num -= 10; 38 | } 39 | } else if (num >= 5) { 40 | if (num >= 9) { 41 | result += "IX"; 42 | num -= 9; 43 | } else { 44 | result += "V"; 45 | num -= 5; 46 | } 47 | } else { 48 | if (num >= 4) { 49 | result += "IV"; 50 | num -= 4; 51 | } else { 52 | result += "I"; 53 | num -= 1; 54 | } 55 | } 56 | } 57 | return result; 58 | } 59 | 60 | console.log(intToRoman(5)); 61 | console.log(intToRoman(50)); 62 | console.log(intToRoman(1235)); 63 | console.log(intToRoman(543)); 64 | -------------------------------------------------------------------------------- /All Other Programs/Navbar.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import './Navbar.css'; 3 | import {Link} from 'react-router-dom'; 4 | 5 | export default function Navbar(){ 6 | return ( 7 |
n
, return the difference between the product of its digits and the sum of its digits.
2 | 3 |
Example 1:
4 | 5 |Input: n = 234 6 | Output: 15 7 | Explanation: 8 | Product of digits = 2 * 3 * 4 = 24 9 | Sum of digits = 2 + 3 + 4 = 9 10 | Result = 24 - 9 = 15 11 |12 | 13 |
Example 2:
14 | 15 |Input: n = 4421 16 | Output: 21 17 | Explanation: 18 | Product of digits = 4 * 4 * 2 * 1 = 32 19 | Sum of digits = 4 + 4 + 2 + 1 = 11 20 | Result = 32 - 11 = 21 21 |22 | 23 |
24 |
Constraints:
25 | 26 |1 <= n <= 10^5
There are n children standing in a line. Each child is assigned a rating value given in the integer array ratings. You are giving candies to these children subjected to the following requirements: Each child must have at least one candy.
2 | Children with a higher rating get more candies than their neighbors.
.
3 |
4 |
Return the minimum number of candies you need to have to distribute the candies to the children.
5 | 6 |7 |
Example 1:
8 | 9 |Input: ratings = [1,0,2] 10 | Output: 5 11 | Explanation: You can allocate to the first, second and third child with 2, 1, 2 candies respectively..12 | 13 | -------------------------------------------------------------------------------- /C++ Programs/135-candy/candy.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/candy/ 2 | 3 | class Solution { 4 | public: 5 | 6 | int candy(vector
Given an array nums
. We define a running sum of an array as runningSum[i] = sum(nums[0]…nums[i])
.
Return the running sum of nums
.
6 |
Example 1:
7 | 8 |Input: nums = [1,2,3,4] 9 | Output: [1,3,6,10] 10 | Explanation: Running sum is obtained as follows: [1, 1+2, 1+2+3, 1+2+3+4].11 | 12 |
Example 2:
13 | 14 |Input: nums = [1,1,1,1,1] 15 | Output: [1,2,3,4,5] 16 | Explanation: Running sum is obtained as follows: [1, 1+1, 1+1+1, 1+1+1+1, 1+1+1+1+1].17 | 18 |
Example 3:
19 | 20 |Input: nums = [3,1,2,10,1] 21 | Output: [3,4,6,16,17] 22 |23 | 24 |
25 |
Constraints:
26 | 27 |1 <= nums.length <= 1000
-10^6 <= nums[i] <= 10^6
You are given an array of unique integers salary
where salary[i]
is the salary of the ith
employee.
Return the average salary of employees excluding the minimum and maximum salary. Answers within 10-5
of the actual answer will be accepted.
6 |
Example 1:
7 | 8 |Input: salary = [4000,3000,1000,2000] 9 | Output: 2500.00000 10 | Explanation: Minimum salary and maximum salary are 1000 and 4000 respectively. 11 | Average salary excluding minimum and maximum salary is (2000+3000) / 2 = 2500 12 |13 | 14 |
Example 2:
15 | 16 |Input: salary = [1000,2000,3000] 17 | Output: 2000.00000 18 | Explanation: Minimum salary and maximum salary are 1000 and 3000 respectively. 19 | Average salary excluding minimum and maximum salary is (2000) / 1 = 2000 20 |21 | 22 |
23 |
Constraints:
24 | 25 |3 <= salary.length <= 100
1000 <= salary[i] <= 106
salary
are unique.Given two non-negative integers low
and high
. Return the count of odd numbers between low
and high
(inclusive).
4 |
Example 1:
5 | 6 |Input: low = 3, high = 7 7 | Output: 3 8 | Explanation: The odd numbers between 3 and 7 are [3,5,7].9 | 10 |
Example 2:
11 | 12 |Input: low = 8, high = 10 13 | Output: 1 14 | Explanation: The odd numbers between 8 and 10 are [9].15 | 16 |
17 |
Constraints:
18 | 19 |0 <= low <= high <= 10^9
Given an array nums
, return true
if the array was originally sorted in non-decreasing order, then rotated some number of positions (including zero). Otherwise, return false
.
There may be duplicates in the original array.
4 | 5 |Note: An array A
rotated by x
positions results in an array B
of the same length such that A[i] == B[(i+x) % A.length]
, where %
is the modulo operation.
8 |
Example 1:
9 | 10 |Input: nums = [3,4,5,1,2] 11 | Output: true 12 | Explanation: [1,2,3,4,5] is the original sorted array. 13 | You can rotate the array by x = 3 positions to begin on the the element of value 3: [3,4,5,1,2]. 14 |15 | 16 |
Example 2:
17 | 18 |Input: nums = [2,1,3,4] 19 | Output: false 20 | Explanation: There is no sorted array once rotated that can make nums. 21 |22 | 23 |
Example 3:
24 | 25 |Input: nums = [1,2,3] 26 | Output: true 27 | Explanation: [1,2,3] is the original sorted array. 28 | You can rotate the array by x = 0 positions (i.e. no rotation) to make nums. 29 |30 | 31 |
32 |
Constraints:
33 | 34 |1 <= nums.length <= 100
1 <= nums[i] <= 100
Table: Products
+-------------+---------+ 4 | | Column Name | Type | 5 | +-------------+---------+ 6 | | product_id | int | 7 | | low_fats | enum | 8 | | recyclable | enum | 9 | +-------------+---------+ 10 | product_id is the primary key for this table. 11 | low_fats is an ENUM of type ('Y', 'N') where 'Y' means this product is low fat and 'N' means it is not. 12 | recyclable is an ENUM of types ('Y', 'N') where 'Y' means this product is recyclable and 'N' means it is not.13 | 14 |
15 | 16 |
Write an SQL query to find the ids of products that are both low fat and recyclable.
17 | 18 |Return the result table in any order.
19 | 20 |The query result format is in the following example.
21 | 22 |23 |
Example 1:
24 | 25 |Input: 26 | Products table: 27 | +-------------+----------+------------+ 28 | | product_id | low_fats | recyclable | 29 | +-------------+----------+------------+ 30 | | 0 | Y | N | 31 | | 1 | Y | Y | 32 | | 2 | N | Y | 33 | | 3 | Y | Y | 34 | | 4 | N | N | 35 | +-------------+----------+------------+ 36 | Output: 37 | +-------------+ 38 | | product_id | 39 | +-------------+ 40 | | 1 | 41 | | 3 | 42 | +-------------+ 43 | Explanation: Only products 1 and 3 are both low fat and recyclable. 44 |45 |
Write a function that reverses a string. The input string is given as an array of characters s
.
You must do this by modifying the input array in-place with O(1)
extra memory.
6 |
Example 1:
7 |Input: s = ["h","e","l","l","o"] 8 | Output: ["o","l","l","e","h"] 9 |
Example 2:
10 |Input: s = ["H","a","n","n","a","h"] 11 | Output: ["h","a","n","n","a","H"] 12 |13 |
14 |
Constraints:
15 | 16 |1 <= s.length <= 105
s[i]
is a printable ascii character.The Fibonacci numbers, commonly denoted F(n)
form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0
and 1
. That is,
F(0) = 0, F(1) = 1 4 | F(n) = F(n - 1) + F(n - 2), for n > 1. 5 |6 | 7 |
Given n
, calculate F(n)
.
10 |
Example 1:
11 | 12 |Input: n = 2 13 | Output: 1 14 | Explanation: F(2) = F(1) + F(0) = 1 + 0 = 1. 15 |16 | 17 |
Example 2:
18 | 19 |Input: n = 3 20 | Output: 2 21 | Explanation: F(3) = F(2) + F(1) = 1 + 1 = 2. 22 |23 | 24 |
Example 3:
25 | 26 |Input: n = 4 27 | Output: 3 28 | Explanation: F(4) = F(3) + F(2) = 2 + 1 = 3. 29 |30 | 31 |
32 |
Constraints:
33 | 34 |0 <= n <= 30
Given a string s
, reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.
4 |
Example 1:
5 |Input: s = "Let's take LeetCode contest" 6 | Output: "s'teL ekat edoCteeL tsetnoc" 7 |
Example 2:
8 |Input: s = "God Ding" 9 | Output: "doG gniD" 10 |11 |
12 |
Constraints:
13 | 14 |1 <= s.length <= 5 * 104
s
contains printable ASCII characters.s
does not contain any leading or trailing spaces.s
.s
are separated by a single space.Given two strings s1
and s2
, return true
if s2
contains a permutation of s1
, or false
otherwise.
In other words, return true
if one of s1
's permutations is the substring of s2
.
6 |
Example 1:
7 | 8 |Input: s1 = "ab", s2 = "eidbaooo" 9 | Output: true 10 | Explanation: s2 contains one permutation of s1 ("ba"). 11 |12 | 13 |
Example 2:
14 | 15 |Input: s1 = "ab", s2 = "eidboaoo" 16 | Output: false 17 |18 | 19 |
20 |
Constraints:
21 | 22 |1 <= s1.length, s2.length <= 104
s1
and s2
consist of lowercase English letters.Given an array of integers nums
which is sorted in ascending order, and an integer target
, write a function to search target
in nums
. If target
exists, then return its index. Otherwise, return -1
.
You must write an algorithm with O(log n)
runtime complexity.
6 |
Example 1:
7 | 8 |Input: nums = [-1,0,3,5,9,12], target = 9 9 | Output: 4 10 | Explanation: 9 exists in nums and its index is 4 11 |12 | 13 |
Example 2:
14 | 15 |Input: nums = [-1,0,3,5,9,12], target = 2 16 | Output: -1 17 | Explanation: 2 does not exist in nums so return -1 18 |19 | 20 |
21 |
Constraints:
22 | 23 |1 <= nums.length <= 104
-104 < nums[i], target < 104
nums
are unique.nums
is sorted in ascending order.Given an array of integers nums
, calculate the pivot index of this array.
The pivot index is the index where the sum of all the numbers strictly to the left of the index is equal to the sum of all the numbers strictly to the index's right.
4 | 5 |If the index is on the left edge of the array, then the left sum is 0
because there are no elements to the left. This also applies to the right edge of the array.
Return the leftmost pivot index. If no such index exists, return -1.
8 | 9 |10 |
Example 1:
11 | 12 |Input: nums = [1,7,3,6,5,6] 13 | Output: 3 14 | Explanation: 15 | The pivot index is 3. 16 | Left sum = nums[0] + nums[1] + nums[2] = 1 + 7 + 3 = 11 17 | Right sum = nums[4] + nums[5] = 5 + 6 = 11 18 |19 | 20 |
Example 2:
21 | 22 |Input: nums = [1,2,3] 23 | Output: -1 24 | Explanation: 25 | There is no index that satisfies the conditions in the problem statement.26 | 27 |
Example 3:
28 | 29 |Input: nums = [2,1,-1] 30 | Output: 0 31 | Explanation: 32 | The pivot index is 0. 33 | Left sum = 0 (no elements to the left of index 0) 34 | Right sum = nums[1] + nums[2] = 1 + -1 = 0 35 |36 | 37 |
38 |
Constraints:
39 | 40 |1 <= nums.length <= 104
-1000 <= nums[i] <= 1000
46 |
Note: This question is the same as 1991: https://leetcode.com/problems/find-the-middle-index-in-array/
47 |Let's call an array arr
a mountain if the following properties hold:
arr.length >= 3
i
with 0 < i < arr.length - 1
such that:
6 | arr[0] < arr[1] < ... arr[i-1] < arr[i]
arr[i] > arr[i+1] > ... > arr[arr.length - 1]
Given an integer array arr
that is guaranteed to be a mountain, return any i
such that arr[0] < arr[1] < ... arr[i - 1] < arr[i] > arr[i + 1] > ... > arr[arr.length - 1]
.
16 |
Example 1:
17 | 18 |Input: arr = [0,1,0] 19 | Output: 1 20 |21 | 22 |
Example 2:
23 | 24 |Input: arr = [0,2,1,0] 25 | Output: 1 26 |27 | 28 |
Example 3:
29 | 30 |Input: arr = [0,10,5,2] 31 | Output: 1 32 |33 | 34 |
35 |
Constraints:
36 | 37 |3 <= arr.length <= 104
0 <= arr[i] <= 106
arr
is guaranteed to be a mountain array.44 | Follow up: Finding the
O(n)
is straightforward, could you find an O(log(n))
solution?