Skip to content

Instantly share code, notes, and snippets.

@Shivani13121007
Shivani13121007 / TiltOfABinaryTree.txt
Created October 22, 2021 06:23
Tilt of a Binary Tree
Description:
Tilt of a node is the absolute value of difference between sum of nodes in it's left subtree and right subtree. Tilt of the whole tree is represented as the sum of tilt of all it's nodes.
Question Name:
Tilt Of a Binary Tree
Question Link:
https://www.pepcoding.com/resources/online-java-foundation/binary-tree/tilt-of-binary-tree/ojquestion
Question Statement:
@Shivani13121007
Shivani13121007 / Is Balanced Tree
Created October 22, 2021 06:47
Is Balanced Tree
Description:
In this video, we explain about balanced binary tree and discuss the solution for the problem where we are required to find if a binary tree is balanced or not
Question Name:
Is Balanced Tree
Article Link:
https://www.pepcoding.com/resources/online-java-foundation/binary-tree/is_balanced_tree/topic
Question Statement:
@Shivani13121007
Shivani13121007 / Is a Binary Search Tree
Last active October 22, 2021 06:52
Is a Binary Search Tree
Description:
In this video, we explain about a binary search tree and discuss the solution for the problem where we are required to find if a tree is a BST or not in minimum time and space complexity.
Question Name:
Is a Binary Search Tree
Article Link:
https://www.pepcoding.com/resources/online-java-foundation/binary-tree/is_a_binary_search_tree/topic
Question Statement:
@Shivani13121007
Shivani13121007 / Largest BST Subtree
Created October 22, 2021 07:06
Largest BST Subtree
Description:
In this video, we have explained about subtree and discuss the solution for the problem where we are required to find the root largest BST subtree in binary tree.
Question Name:
Largest BST Subtree
Article Link:
https://www.pepcoding.com/resources/online-java-foundation/binary-tree/largest_bst_subtree/topic
Question Statement:
@Shivani13121007
Shivani13121007 / Binary Search Tree Introduction
Created October 22, 2021 07:11
Binary Search Tree Introduction
Description:
In this video, we will introduce the Binary Search Tree, a variation of Binary tree where the left node is always smaller than the right node and the left subtree is always smaller than the right subtree.
Video Name:
Binary Search Tree-Introduction
Video Link:
https://www.youtube.com/watch?v=wE5nFfdr7Ls&list=PL-Jc9J83PIiGl_-iS5k7R7SZoZPt0Fab2
@Shivani13121007
Shivani13121007 / How Many Numbers Are Smaller Than the Current Number
Created October 23, 2021 16:12
How Many Numbers Are Smaller Than the Current Number
class Solution {
public int[] smallerNumbersThanCurrent(int[] nums) {
int[] ans = new int[nums.length];
// Brute Technique
// for(int i=0;i<nums.length;i++)
// {
// int c=0;
// for(int j=0;j<nums.length;j++)
@Shivani13121007
Shivani13121007 / Minimum Number of Moves to Seat Everyone
Created October 23, 2021 16:16
Minimum Number of Moves to Seat Everyone
class Solution {
public int minMovesToSeat(int[] seats, int[] students) {
Arrays.sort(seats);
Arrays.sort(students);
int ans = 0;
for(int i=0;i<seats.length;i++)
{
ans+= Math.abs(seats[i] - students[i]);
@Shivani13121007
Shivani13121007 / Sorting the Sentence
Created October 23, 2021 16:20
Sorting the Sentence
class Solution {
public String sortSentence(String s) {
String[] arr = s.split(" ");
String[] res = new String[arr.length];
String fa = "";
for(int i=0;i<arr.length;i++)
{
String str = arr[i];
String toAdd = "";
@Shivani13121007
Shivani13121007 / Maximum Product Difference Between Two Pairs
Created October 23, 2021 16:22
Maximum Product Difference Between Two Pairs
class Solution {
public int maxProductDifference(int[] nums) {
int n = nums.length;
Arrays.sort(nums);
int a = nums[0];
int b = nums[1];
int c = nums[n-1];
int d = nums[n-2];
@Shivani13121007
Shivani13121007 / Maximum Product of Two Elements in an Array
Created October 23, 2021 16:30
Maximum Product of Two Elements in an Array
class Solution {
public int maxProduct(int[] nums) {
int n = nums.length;
Arrays.sort(nums);
int res = (nums[n-1] -1) * (nums[n-2] -1);
return res;
}
}