Public
Edited
Mar 1, 2023
Insert cell
Insert cell
{
let test = new List();

test.add(30);
test.add(12);
test.add(25);

return test.print();
}
Insert cell
class Node {
constructor(val, next) {
this.val = val || null;
this.next = next || null;
}
}
Insert cell
class List {
constructor() {
this.head = null;
}
add(value) {
if (!this.head) {
this.head = new Node(value);

return this.head;
}

let current = this.head;

while (current.next) {
current = current.next;
}

current.next = new Node(value);

return this.head;
}
print() {
let values = [];

if (!this.head) {
return values;
}

let current = this.head;

while (current) {
values.push(current.val);
current = current.next;
}

return values;
}
}
Insert cell
maxSubArray([-2, 1, -3, 4, -1, 2, 1, -5, 4])
Insert cell
maxSubArray = function (nums) {
let current = nums[0];
let subarray = [];

for (let i = 1; i < nums.length; i++) {
if (nums[i] > current) {
current = nums[i];
subarray = [nums[i]];
} else {
current = current + nums[i];
subarray.push(nums[i]);
}
}

return subarray;

return current;
}
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more