CoolFace
Datasetpublic

FPEvalDataset/LeetCodeProblem

sourceHugging Faceupdated 8mo agoView on Hugging Face
0likes305downloads
1{2    "id": 2316,3    "name": "count_hills_and_valleys_in_an_array",4    "difficulty": "Easy",5    "link": "https://leetcode.com/problems/count-hills-and-valleys-in-an-array/",6    "date": "1647129600000",7    "task_description": "You are given a **0-indexed** integer array `nums`. An index `i` is part of a **hill** in `nums` if the closest non-equal neighbors of `i` are smaller than `nums[i]`. Similarly, an index `i` is part of a **valley** in `nums` if the closest non-equal neighbors of `i` are larger than `nums[i]`. Adjacent indices `i` and `j` are part of the **same** hill or valley if `nums[i] == nums[j]`. Note that for an index to be part of a hill or valley, it must have a non-equal neighbor on **both** the left and right of the index. Return the number of hills and valleys in `nums`. **Example 1:** ``` **Input:** nums = [2,4,1,1,6,5] **Output:** 3 **Explanation:** At index 0: There is no non-equal neighbor of 2 on the left, so index 0 is neither a hill nor a valley. At index 1: The closest non-equal neighbors of 4 are 2 and 1. Since 4 > 2 and 4 > 1, index 1 is a hill. At index 2: The closest non-equal neighbors of 1 are 4 and 6. Since 1 < 4 and 1 < 6, index 2 is a valley. At index 3: The closest non-equal neighbors of 1 are 4 and 6. Since 1 < 4 and 1 < 6, index 3 is a valley, but note that it is part of the same valley as index 2. At index 4: The closest non-equal neighbors of 6 are 1 and 5. Since 6 > 1 and 6 > 5, index 4 is a hill. At index 5: There is no non-equal neighbor of 5 on the right, so index 5 is neither a hill nor a valley. There are 3 hills and valleys so we return 3. ``` **Example 2:** ``` **Input:** nums = [6,6,5,5,4,1] **Output:** 0 **Explanation:** At index 0: There is no non-equal neighbor of 6 on the left, so index 0 is neither a hill nor a valley. At index 1: There is no non-equal neighbor of 6 on the left, so index 1 is neither a hill nor a valley. At index 2: The closest non-equal neighbors of 5 are 6 and 4. Since 5 < 6 and 5 > 4, index 2 is neither a hill nor a valley. At index 3: The closest non-equal neighbors of 5 are 6 and 4. Since 5 < 6 and 5 > 4, index 3 is neither a hill nor a valley. At index 4: The closest non-equal neighbors of 4 are 5 and 1. Since 4 < 5 and 4 > 1, index 4 is neither a hill nor a valley. At index 5: There is no non-equal neighbor of 1 on the right, so index 5 is neither a hill nor a valley. There are 0 hills and valleys so we return 0. ``` **Constraints:** `3 <= nums.length <= 100` `1 <= nums[i] <= 100`",8    "public_test_cases": [9        {10            "label": "Example 1",11            "input": "nums = [2,4,1,1,6,5]",12            "output": "3 "13        },14        {15            "label": "Example 2",16            "input": "nums = [6,6,5,5,4,1]",17            "output": "0 "18        }19    ],20    "private_test_cases": [21        {22            "input": [23                91,24                96,25                14,26                76,27                60,28                3329            ],30            "output": 331        },32        {33            "input": [34                58,35                18,36                27,37                35,38                91,39                97,40                69,41                83,42                90,43                65,44                55,45                100,46                37,47                29,48                56,49                49,50                951            ],52            "output": 853        },54        {55            "input": [56                56,57                24,58                19,59                38,60                82,61                51,62                3,63                71,64                24,65                57,66                5,67                75,68                14,69                28,70                70,71                98,72                78,73                97,74                59,75                45,76                84,77                95,78                12,79                16,80                58,81                96,82                55,83                6,84                80,85                14,86                15,87                81,88                84,89                13,90                2,91                65,92                64,93                57,94                59,95                15,96                61,97                36,98                72,99                13,100                21,101                88,102                64,103                92,104                89,105                37,106                59,107                47,108                57,109                84,110                21,111                94,112                19,113                32,114                82,115                36,116                39,117                85,118                72,119                35,120                77,121                48,122                61,123                25,124                45,125                9,126                3,127                29,128                89,129                72,130                74,131                34,132                19,133                15,134                28,135                47,136                90,137                34,138                20,139                44,140                48141            ],142            "output": 55143        },144        {145            "input": [146                82,147                61,148                25,149                68,150                53,151                69,152                15,153                43,154                7,155                13,156                54,157                28,158                45,159                93,160                34,161                12,162                21,163                97,164                96,165                54,166                74,167                89,168                53,169                30,170                89,171                33,172                7,173                70,174                29,175                61,176                76,177                15,178                48,179                32,180                18,181                6182            ],183            "output": 22184        },185        {186            "input": [187                92,188                53,189                38,190                82,191                79,192                72,193                95,194                77,195                4,196                39,197                4,198                30,199                82,200                2,201                82,202                55,203                99,204                5,205                1,206                35,207                74,208                95,209                69,210                44,211                60,212                14,213                34,214                33,215                37,216                61,217                6,218                47,219                93,220                28,221                99,222                40,223                64,224                64,225                36,226                63,227                37,228                88,229                14,230                89,231                8,232                45,233                12,234                59,235                79,236                60,237                5238            ],239            "output": 36240        },241        {242            "input": [243                99,244                1,245                8,246                27,247                83,248                77,249                2,250                27,251                1,252                17,253                16,254                51,255                42,256                6,257                98,258                59,259                8,260                43,261                44,262                28,263                50,264                23,265                73,266                49,267                52,268                87,269                15,270                41,271                50,272                72,273                99,274                31,275                14,276                53,277                62,278                62,279                25280            ],281            "output": 22282        },283        {284            "input": [285                51,286                58,287                64,288                32,289                67,290                65,291                62,292                81,293                85,294                93,295                5,296                27,297                20,298                16,299                97,300                26,301                32,302                70,303                13,304                34,305                64,306                45,307                95,308                18,309                41,310                70,311                51,312                14,313                46,314                4,315                33,316                75,317                36,318                28,319                25,320                92,321                31,322                48,323                94,324                47,325                11,326                14,327                99,328                23,329                7,330                38,331                92,332                84,333                47,334                89,335                75,336                3,337                31,338                36,339                28,340                48,341                12342            ],343            "output": 35344        },345        {346            "input": [347                65,348                68,349                61,350                31,351                53,352                34,353                26,354                24,355                39,356                65,357                75,358                27,359                47,360                2,361                20,362                20,363                9,364                87,365                93,366                14,367                14,368                54,369                26,370                4,371                26,372                3,373                34,374                21,375                66,376                26,377                4,378                99,379                10,380                16,381                22,382                38,383                99,384                37,385                28,386                87,387                19,388                56,389                16,390                71,391                40,392                84,393                13,394                41,395                20,396                86,397                6,398                94,399                7,400                11401            ],402            "output": 38403        },404        {405            "input": [406                30,407                20,408                65,409                65,410                55,411                98,412                84,413                91,414                21,415                34,416                92,417                26,418                52,419                69,420                19,421                32,422                70,423                24,424                80,425                49,426                76,427                21,428                98,429                30,430                74,431                78,432                69,433                13,434                14,435                39,436                37,437                85,438                39,439                11,440                74441            ],442            "output": 25443        },444        {445            "input": [446                57,447                66,448                50,449                62,450                87,451                4,452                28,453                38,454                53,455                89,456                16,457                88,458                55,459                62,460                79,461                96,462                60,463                92,464                58,465                59,466                58,467                41,468                66,469                19,470                66,471                12,472                99,473                59,474                27,475                51,476                86,477                73,478                46,479                47,480                39,481                24,482                82,483                91,484                9,485                86,486                66,487                86,488                62,489                14,490                40,491                15,492                84,493                64,494                92,495                65,496                78,497                16,498                29,499                80,500                68501            ],502            "output": 39503        }504    ],505    "haskell_template": "countHillValley :: [Int] -> Int\ncountHillValley nums ",506    "ocaml_template": "let countHillValley (nums: int list) : int =  ",507    "scala_template": "def countHillValley(nums: List[Int]): Int = { \n    \n}",508    "java_template": "public static int countHillValley(List<Integer> nums) {\n\n}",509    "python_template": "class Solution(object):\n    def countHillValley(self, nums):\n        \"\"\"\n        :type nums: List[int]\n        :rtype: int\n        \"\"\"\n        "510}