"function isPalindrome(s, start, end) {
while (s[start] === s[end] && end >= start) {
start++;
end--;
}
return end <= start;
}
function longestPalindromicSubstring(s) {
let longestPalindrome = '';
for (let i=0; i < s.length; i++) {
let j = s.length-1;
while (s[i] !== s[j] && i <= j) {
j--;
}
if (s[i] === s[j]) {
if (isPalindrome(s, i, j)) {
const validPalindrome = s.substring(i, j+1"
Tiago R. - "function isPalindrome(s, start, end) {
while (s[start] === s[end] && end >= start) {
start++;
end--;
}
return end <= start;
}
function longestPalindromicSubstring(s) {
let longestPalindrome = '';
for (let i=0; i < s.length; i++) {
let j = s.length-1;
while (s[i] !== s[j] && i <= j) {
j--;
}
if (s[i] === s[j]) {
if (isPalindrome(s, i, j)) {
const validPalindrome = s.substring(i, j+1"See full answer
Data Engineer
Data Structures & Algorithms
+3 more
🧠Want an expert answer to a question? Saving questions lets us know what content to make next.
"Ensure immediate safety: The first priority is to secure the vehicle and its occupants by stopping the engine, activating hazard lights, and unlocking doors.
Assess the situation: The car evaluates the extent of damage, determines its location, and checks on the status of passengers.
Call for help: Based on the assessment, the car calls emergency services if necessary and notifies the manufacturer.
Collect and store accident data: This is crucial for later analysis and potential legal pu"
Surbhi G. - "Ensure immediate safety: The first priority is to secure the vehicle and its occupants by stopping the engine, activating hazard lights, and unlocking doors.
Assess the situation: The car evaluates the extent of damage, determines its location, and checks on the status of passengers.
Call for help: Based on the assessment, the car calls emergency services if necessary and notifies the manufacturer.
Collect and store accident data: This is crucial for later analysis and potential legal pu"See full answer
"Basic Approach
As BST inorder traversal will result in a sequence of increasing order. Store that order in a vector and get the k-1 index to get the Kth smallest element, similarly access the N-K+1 th element will be the Kth largest element
Time Complexity: O(n)
Space Complexity O(n)
Space Optimized Approach
For Kth smallest , start inorder traversal, and keep a counter, decrement the counter when you access the node element. When the counter turns 0 that elementwill be the Kth smal"
Saurabh S. - "Basic Approach
As BST inorder traversal will result in a sequence of increasing order. Store that order in a vector and get the k-1 index to get the Kth smallest element, similarly access the N-K+1 th element will be the Kth largest element
Time Complexity: O(n)
Space Complexity O(n)
Space Optimized Approach
For Kth smallest , start inorder traversal, and keep a counter, decrement the counter when you access the node element. When the counter turns 0 that elementwill be the Kth smal"See full answer
"Overfitting is the condition where your model is giving an unexpectedly higher accuracy because of its training in a small database and not getting exposed to anu different type of database while testing"
Bhavya V. - "Overfitting is the condition where your model is giving an unexpectedly higher accuracy because of its training in a small database and not getting exposed to anu different type of database while testing"See full answer