"Reversing a linked list is a very popular question. We have two approaches to reverse the linked list: Iterative approach and recursion approach.
Iterative approach (JavaScript)
function reverseLL(head){
if(head === null) return head;
let prv = null;
let next = null;
let cur = head;
while(cur){
next = cur.next; //backup
cur.next = prv;
prv = cur;
cur = next;
}
head = prv;
return head;
}
Recursion Approach (JS)
function reverseLLByRecursion("
Satyam S. - "Reversing a linked list is a very popular question. We have two approaches to reverse the linked list: Iterative approach and recursion approach.
Iterative approach (JavaScript)
function reverseLL(head){
if(head === null) return head;
let prv = null;
let next = null;
let cur = head;
while(cur){
next = cur.next; //backup
cur.next = prv;
prv = cur;
cur = next;
}
head = prv;
return head;
}
Recursion Approach (JS)
function reverseLLByRecursion("See full answer
"This was a 60 minute assessment. The clock is ticking and you're being observed by a senior+ level engineer. Be ready to perform for an audience.
The implementation for the system gets broken up into three parts:
Implement creating accounts and depositing money into an account by ID
Implement transferring money with validation to ensure the accounts for the transfer both exist and that the account money is being removed from has enough money in it to perform the transfer
Implement find"
devopsjesus - "This was a 60 minute assessment. The clock is ticking and you're being observed by a senior+ level engineer. Be ready to perform for an audience.
The implementation for the system gets broken up into three parts:
Implement creating accounts and depositing money into an account by ID
Implement transferring money with validation to ensure the accounts for the transfer both exist and that the account money is being removed from has enough money in it to perform the transfer
Implement find"See full answer
"naive solution:
def countprefixpairs(words):
n = len(words)
count = 0
for i in range(n):
for j in range(i + 1, n):
if words[i].startswith(words[j]) or words[j].startswith(words[i]):
count += 1
return count
using tries for when the list of words is very long:
from collections import Counter
class TrieNode:
def init(self):
self.children = {}
self.count = 0 # To count the number of words ending at this node"
Anonymous Unicorn - "naive solution:
def countprefixpairs(words):
n = len(words)
count = 0
for i in range(n):
for j in range(i + 1, n):
if words[i].startswith(words[j]) or words[j].startswith(words[i]):
count += 1
return count
using tries for when the list of words is very long:
from collections import Counter
class TrieNode:
def init(self):
self.children = {}
self.count = 0 # To count the number of words ending at this node"See full answer