मुख्य कंटेंट तक स्किप करें
🌟 Loving the project? Support our open-source journey with a
Star on GitHub
!
एल्गो (Algo)
Tutorials
Interview Engine
System Preparation
Verification Roadmap
Core Matrix Questions
Real-World Implementation
Contribution Tracker
Evaluation Pools
Code Challenges
Practice Arena
Concept Quizzes
Compiled Solutions
Community Hub
Telemetry & Systems
Contributors Wall
Global Leaderboard
Milestones & Badges
Infrastructure Patrons
Ecosystem Labs
Code Playground
Algorithm Visualizer
Recursion Visualizer
Success Stories
Public Discussions
Extended Assets
FAQ
Blogs
हिन्दी
English
हिन्दी
खोज करें
Sign Up
Back to Challenges
Longest Increasing Subsequence (LIS)
Medium
25 min
problem
solution
Longest Increasing Subsequence (LIS)
Given an integer array nums, return the length of the longest strictly increasing subsequence.
Examples
Input:
nums = [10,9,2,5,3,7,101,18]
Output:
4
The longest increasing subsequence is [2,3,7,101], length 4.
Input:
nums = [0,1,0,3,2,3]
Output:
4
The longest increasing subsequence is [0,1,2,3].
Constraints
•
1 <= nums.length <= 2500
•
-10^4 <= nums[i] <= 10^4
Complexity Analysis
Time
O(n^2)
nested loop DP. Note that O(n log n) is possible using binary search.
Space
O(n)
DP array.
Show Hint
Test Cases
#1 Standard LIS
Input:
[10,9,2,5,3,7,101,18]
Expected:
4
#2 Array with duplicate values
Input:
[0,1,0,3,2,3]
Expected:
4
#3 All identical values
Input:
[7,7,7,7,7]
Expected:
1
JavaScript
Run Code
/** * @param {number[]} nums * @return {number} */ function lengthOfLIS(nums) { // Your code here } console.log(lengthOfLIS([10,9,2,5,3,7,101,18])); // Expected: 4
Output
Click "Run Code" to see output here...