Skip to content

Instantly share code, notes, and snippets.

View Harsh78Anand's full-sized avatar
🎯
Focusing

Harsh Anand Harsh78Anand

🎯
Focusing
  • Pepcoding Education Private Limited
  • Noida, UP, India
View GitHub Profile
@Harsh78Anand
Harsh78Anand / FAQ
Last active November 15, 2021 15:11
pepcoding.com Quick tour to conditions and loops
#FAQ
Q1. When do we use conditional statements?
Ans. Conditional statements are decision-making statements so we can use these statements when we want to execute a block of code when the given condition is true or false.
Q2. What does the elif keyword do in Python?
Ans. Elif keyword basically contains a condition which is executed or checked if the previous conditions were not true.
Q3. How do we implement 'logical and' in Python?
Ans. In python logical and can be implemented through 'and' keyword which basically combines conditional statements much like the and operation in logic gates.
@Harsh78Anand
Harsh78Anand / FAQ
Last active November 15, 2021 15:28
pepcoding.com Functions
#FAQ
Q1. How do we define a function in Python?
Ans. In python, functions can be defined using the def keyword.
Q2. What is the difference between parameter and argument?
Ans. Although they are used for the same thing, information that are passed into a function, a parameter is the variable listed inside the parentheses in the function definition while an argument is the value that is sent to the function when it is called.
Q3. Where are functions stored in Python?
Ans. The function calls and the references are stored in stack memory and all the values objects are stored in the heap.
@Harsh78Anand
Harsh78Anand / FAQ
Created November 15, 2021 08:37
pepcoding.com Strings
#FAQ
Q1. Are strings in python mutable?
Ans. Strings are not mutable in Python i.e string is an immutable data type which means that its value cannot be updated.
Q2. How to count total number of characters in a string in python?
Ans. We can use 'len()' for this. 'len(string)' will give us the number of characters in a string variable 'string'.
Q3. Can an integer be added to a string in Python?
Ans. Unlike languages like Java, integer cannot be added to a string in Python, it will throw a TypeError.
@Harsh78Anand
Harsh78Anand / FAQ
Created November 15, 2021 07:59
pepcoding.com Variables, Data Types
#FAQ
Q1. Why variables are not declared with data type in Python?
Ans. This is because Python is a dynamic typed language, which means we don't need to mention the variable type or declare before using it and every variable is treated as an object.
Q2. How do you declare local and global variables in Python?
Ans. Global variables are those which are not defined inside any function,but can be referenced inside it and have a global scope. We can also make a variable global using 'global' keyword. When we define a variable inside a function,it becomes local and its scope is limited to that function only.
Q3. What is the difference between mutable and immutable data types?
Ans. An immutable object cannot be modified once created. Whereas, mutable data types can be modified, we can change their lengths, modify their values and so on. An example of a mutable object in Python is the list. Tuple is an example of immutable object.
@Harsh78Anand
Harsh78Anand / FAQ
Created November 8, 2021 07:05
Print Increasing Decreasing
#FAQ
Q1. What is the faith of this question?
Ans. We must have faith that if our code can give us an output for n=i, then it can definitely give us an output for n=i-1. We just need to believe the faith and don't focus on "HOW" that will happen.
Q2. Why do we use print statement twice?
Ans. Because the first print statement prints numbers from n in decreasing order upto 1 and then the second print does the vice versa, so first print is used before recusive call and the second after the call.
Q3. Why is n==0 the base condition?
Ans. We don't want to print 0, and it will cause the recursive stack to overflow, so it is taken as base case.
@Harsh78Anand
Harsh78Anand / FAQ
Created November 8, 2021 06:34
Write PriorityQueue using Heap
#FAQ
Q) What is the time complexity of up-heapify process?
Ans. The time complexity for up-heapify process is O(logn).
Q) What is Heap Order Property (HOP)?
Ans. This means that the priority of a parent is always greater than its child. And to be specific, the priority of either child is not pre decided. This property basically helps us to achieve the most efficient time complexity of the peek() function.
Q) What is Complete Binary Tree (CBT)?
Ans. Supposing that the height of the tree is h, then according to this property, at least h-1 levels of the Heap should be completely filled. And the last level should be filled from left to right.
@Harsh78Anand
Harsh78Anand / FAQ
Created October 27, 2021 08:13
Matrix Multiplication
#FAQ
Q) What is the space complexity of this question and why?
Ans. The space complexity is O(n^2) as 2D arrays are used to store numbers, therefore space complexity is quadratic.
Q) If Matrix A is of order X*Y and Matrix B is of order M*N, then what is the order of the Matrix A*B given that Y=M?
Ans. The order would be X*N as the Matrix A*B is of order X*N as it is given that Y=M i.e. number of columns in Matrix A is equal to total number of rows in matrix B. So the Matrix A*B must have X number of rows and N number of columns.
@Harsh78Anand
Harsh78Anand / FAQ
Created October 26, 2021 13:16
Reverse Linkedlist Pointer Recursive
#FAQ
Q) What does the reversePR() function do?
Ans. When reversePRHelper() is returned to reversePR(), head next is changed to null because after reversing the linked list, the original head becomes the tail.
This function swaps the head and the tail pointers using a temp Node.
Q) Is it necessary that we start to change our pointers from the end?
Ans. Yes, it is necessary that we start to change our pointers from the end so that our Linked List doesn't break in between and we therefore fail to complete the given task.
Q) When will the base case hit in this problem?
@Harsh78Anand
Harsh78Anand / FAQ
Last active October 26, 2021 11:36
#FAQ
Q) Can we start our recursion from last index in this question?
Ans. Yes, we can, in that case we start from the last index of the array and we return the first index where we find the required number otherwise we return -1.
Q) Why do we need the base condition where we check if idx==arr.length?
Ans. This base case is required to prevent the recursion from moving to out of bounds for the test cases where the given element is not present in the array.
Q) What is the time complexity of the question and why?
Ans. The time complexity of the problem is O(n) as n (array's length) calls are made and work is done corresponding to these n calls.
Description:
In this video, we discuss the Arrange Buildings problem where we are required to find all the arrangements of buildings on two sides of a road such that no two buildings are side by side. This problem is similar to the Count Binary Strings.
Question Name:
Arrange Buildings
Question Link:
Pepcoding Portal Link: https://www.pepcoding.com/resources/online-java-foundation/dynamic-programming-and-greedy/arrange-buildings-official/ojquestion