Welcome to the fifth PHP coding puzzle !

You are given an array of integers, and you need to write a PHP function that will find the length of the longest increasing subsequence in the array. A subsequence is a subset of the array that maintains the relative order of the elements, but not necessarily their contiguousness.

For example, given the array [10, 9, 2, 5, 3, 7, 101, 18], the longest increasing subsequence is [2, 3, 7, 101], which has length 4.

Here’s the function signature:

/**
 * @param int[] $nums
 *
 * @return int
 */
function lengthOfLIS(array $nums): int
{
  // Your code here
}

You can assume that the input array is non-empty.

The solution is already available in the next page 😉 Feel free to share with us your solution here in comments or Github.

2 COMMENTS

  1. The signature should be:

    /**
    * @param non-empy-list
    *
    * @return list
    */
    function lengthOfLIS(array $nums): array
    {
    // Your code here
    }

LEAVE A REPLY

Please enter your comment!
Please enter your name here