Question

input array: nums = [-1,0,1,2,-1,-4]
sort input array: nums = [-4,-1,-1,0,1,2]

Encapsulation

Encapsulation is binding variables and methods together. In encapsulation, the variables of a class are private, other classes can only access they (modify and review the variables values) through the public getter and setter methods you provided. So encapsulation is also known as data hiding.

public class Encap{   private String name   public String getName(){
return name…

Question


Stacks

Definition

“Stack is a linear data structure which follows a particular order in which the operations are performed. The order may be LIFO(Last In First Out) or FILO(First In Last Out).”

Implement Stacks Using Arrays

class Stack{
constructor(){
this.items = []
}
isEmpty(){
return this.items.length === 0
}
push(data){
this.items.push(data)
}
pop(){
if(this.isEmpty()){
return null
}
return this.items.pop()
}
}
let s = new Stack()
s.push(1)
s.push(2)
s.push(3)
console.log(s)…

Time Complexity

“In computer science, the time complexity is the computational complexity that describes the amount of time it takes to run an algorithm.”

 5n² + 3n + log2(n)


Question:

How to find a palindromic substring (expand around center)

Starting from the center of a substring to evaluate wether the substring is a palindrome. If the letter on the left side of the center s[center-1] equals the letter on the right side of the center s[center+1], we keep moving to the next letter on each side, until we hit unequal:

s[center…


primitive values

JavaScript sets a value to one of six primitive data types:

  • Undefined (a variable with no defined value)
  • Null (a single null value)
  • Boolean (true or false)
  • Number (this includes Infinity and NaN – not a number!)
  • String (textual data)
  • Symbol (a unique and immutable primitive new to ES6/2015)

Falsy values

  • false

Scope

Var can be used for declaring globally scoped variable and function scoped variable.

var a = 1
function example(){
var b = 2
console.log(b) // 2
}
console.log(a) // 1

Key Points:

Closure is a function returns another function.

Example:

We have an outer function called outer(). It creates a local variable called counter and a function called inner(). …

Cindy Zheng

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store