OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Why I am getting an error "Output Limit Exceeded" in Javascript?

  • Thread starter Thread starter Harsh Mishra
  • Start date Start date
H

Harsh Mishra

Guest
I am trying to solve a problem of LinkedList on leetcode in javascript language but out of 86 test cases 74 cases are passed but at 75 I am getting an error Output Limit Exceeded.

Problem:

Code:
Given the head of a singly linked list, return true if it is a palindrome.

Examples:

Code:
Input: head = [1,2,2,1]
Output: true

Input: head = [1,2]
Output: false

My code:

Code:
let array = [];
let list = head;
while (list) {
  array.push(list.val)
  console.log("array1", array)
  list = list.next;
}

let list2 = head;
while (list2) {
  let out = array.pop()
  if (out === list2.val) {
    list2 = list2.next;
  } else {
    return false
  }
}

return true

Last executed input: [3,8,9,3,2,8,9,1,8,9,9,8,5,2,5,4,4,4,3,9,7,5,0,5,8,6,3,3,8,0,7,3,7,7,1,1,1,7,0,2,8,1,8,7,2,9,5,2,9,7,4,8,...]

I am not able to understand why I am getting a Limit exceeded error? Is it due to too many inputs? Or Issue is in my code? If the issue is with inputs then How can I solve this problem in Javascript?

<p>I am trying to solve a problem of <code>LinkedList</code> on leetcode in javascript language but out of <code>86</code> test cases <code>74</code> cases are passed but at <code>75</code> I am getting an error <code>Output Limit Exceeded</code>.</p>
<p>Problem:</p>
<pre><code>Given the head of a singly linked list, return true if it is a palindrome.
</code></pre>
<p>Examples:</p>
<pre><code>Input: head = [1,2,2,1]
Output: true

Input: head = [1,2]
Output: false
</code></pre>
<p>My code:</p>
<pre><code>let array = [];
let list = head;
while (list) {
array.push(list.val)
console.log("array1", array)
list = list.next;
}

let list2 = head;
while (list2) {
let out = array.pop()
if (out === list2.val) {
list2 = list2.next;
} else {
return false
}
}

return true
</code></pre>
<p><code>Last executed input:</code>
[3,8,9,3,2,8,9,1,8,9,9,8,5,2,5,4,4,4,3,9,7,5,0,5,8,6,3,3,8,0,7,3,7,7,1,1,1,7,0,2,8,1,8,7,2,9,5,2,9,7,4,8,...]</p>
<p>I am not able to understand why I am getting a <code>Limit exceeded error</code>? Is it due to too many inputs? Or Issue is in my code? If the issue is with inputs then How can I solve this problem in Javascript?</p>
 

Latest posts

Top