Search This Blog

The Unplanned Marriage Meeting

 I was sleeping with a blanket over me when I suddenly heard the sound of uninvited guests at home. I thought it was okay, as my mum was there to attend to them, so I relaxed and went back to sleep. 

However, to my surprise, they were actually there to inquire about me. They had come to see me for their nephew. It was a big shock, as I was unprepared and hadn't taken a bath or changed out of my nightdress. They didn't give me a chance to prepare myself. 

My mum was also taken aback when the guests asked to see me. She urgently called for me to come quickly. I hastened to get ready, tidying my hair and spritzing some perfume to eliminate any evidence of not having taken a bath. 

When I went to meet the guests, I politely offered them water and tea, even though I'm not a fan of the latter. 

In India, it's customary to offer tea to guests, so I made an effort to make it, despite having not made tea for several years. 

The meeting went well, despite a humorous start. My arranged marriage matchmakers arrived and saw me dressed in a nightgown instead of looking my best.

Love Babbar's C++ DSA Lecture's Solutions

  1. Lecture: 1 Homework Solutions
  2. Lecture: 2 Homework Solutions
  3. Lecture: 3 Homework Solutions
  4. Lecture: 4 Homework Solutions
  5. Lecture: 5 Homework Solutions
  6. Lecture: 6 Homework Solutions
  7. Lecture: 7 Homework Solutions

Homework of Video 4 ( Solving Pattern Questions (Part-2) ) - Love babbar

1. Write a program to print this pattern:

1
2 3
4 5 6
7 8 9 10


2. Write a program to print this pattern:

1
2 3
3 4 5
4 5 6 7


3. Write a program to print this pattern:

A B C
A B C
A B C


4. Write a program to print this pattern:

A B C
D E F
G H I


5. Write a program to print this pattern:

A B C
B C D
C D E


6. Write a program to print this triangular pattern:

A
B B
C C C


7. Write a program to print this triangular pattern:

D
C D
B C D
A B C D


8. Write a program to print this square matrix pattern:

****
***
**
*


9. Write a program to print this square matrix pattern:

****
***
**
*



10. Write a program to print this square matrix pattern:

1111
222
33
4


11. Write a program to print this square matrix pattern:

1
22
333
4444


12. Write a program to print this square matrix pattern:

1234
234
34
4


13. Write a program to print this square matrix pattern:

1
23
456
78910


14. Write a program to print this square matrix pattern:

1234554321
1234**4321
123****321
12******21
1********1

Homework of Video 3 ( If-Else, While loop & Lots of Patterns (Part-1) ) - Love babbar


1. Why do we write namespace std & iostream as the program's header?

Ans. These are pre-built libraries where a code related to performing a certain task is placed So that, C++ can work effectively.

a. Using namespace std: There are a bunch of namespaces & out of them we are using std that makes the computer know that we are using cout. Basically, an identifier conflict resolver.

b. #include <iostream> : This header contains the programs of input & output functions like cout,cin etc. #include asks to include iostream


2. Guess the output :


Ans: NINEYPOSITIVE



Ans: 3


Ans: Love24

3. Write a code that accepts char ch. 

  • Prints this is the lowercase or small case if lies in between 'a' - 'z'
  • Prints this is uppercase  if lies in between 'A' - 'Z'
  • Prints this is numeric if lies in between '0' - '9'


4. Input N and print the sum of all the even numbers lying in 1 to N.



5.  Write a program to convert the temperature into:
  • Fahrenheit to celsius
  • Celsius to Fahrenheit

Python Mail Merge Project - Automating Recipient Writing in a Letter


Project Description:
  1. Automates the recipient writing part in the same letter.
  2. Recipient names are given in a separate file named invited_names.txt
  3. A sample letter is given in a separate file named starting_letter.txt
  4. Code is to be written inside main.py whose purpose is to fetch the sample letter, replace the [name] in a sample letter with recipient names &  generate an individual letter following this naming convention: letter_for_{recipient_name}.txt
  5. The number of names given in invited_names.txt file generates a similar number of letters. Suppose, 5 names are given in invited_names.txt then, 5 letters will be generated.


Folder Structure:

Folder Structure

Output:






./Input/Letters/starting_letter.txt


./Input/Names/invited_names.txt


./Output/ReadyToSend/example.txt


main.py

Crossing the Turtle : Python Turtle Project for Beginners

 

Game Rules:

  1. One turtle of unique color can only move forward.
    • Neither left nor right. Turtle cannot even move backward.    
  2. Turtle has to save itself from the collision with cars.
  3. If crosses all the cars, its level increases & along with all the car's speed!
  4. Random count cars & each car of random color are coming from the left & right.
  5. The scoreboard is maintained for every level.

How the game looks like?


crossing the turtle -gif


main.py



player.py



car_manager.py



scoreboard.py

Blind 75 Must Do Leetcode Python 3 Solutions

Blind 75 Must Do Leetcode Python 3 Solutions

Hashing to Solutions:
  1. Two Sum
  2. Longest Substring Without Repeating Characters
  3. Longest Palindromic Substring
  4. Container With Most Water
  5. 3Sum
  6. Remove Nth Node From End of List
  7. Valid Parentheses
  8. Merge Two Sorted Lists
  9.  Merge k Sorted Lists
  10. Search in Rotated Sorted Array
  11. Combination Sum
  12. Rotate Image
  13. Group Anagrams
  14. Maximum Subarray
  15. Spiral Matrix
  16. Jump Game
  17. Merge Intervals
  18. Insert Interval
  19. Unique Paths
  20. Climbing Stairs
  21. Set Matrix Zeroes
  22. Minimum Window Substring
  23. Word Search
  24. Decode Ways
  25. Validate Binary Search Tree
  26. Same Tree
  27.  Binary Tree Level Order Traversal
  28. Maximum Depth of Binary Tree
  29. Construct Binary Tree from Preorder and Inorder Traversal
  30. Best Time to Buy and Sell Stock
  31. Binary Tree Maximum Path Sum
  32. Valid Palindrome
  33. Longest Consecutive Sequence
  34. Clone Graph
  35. Word Break
  36. Linked List Cycle
  37. Reorder List
  38. Maximum Product Subarray
  39. Find Minimum in Rotated Sorted Array
  40. Reverse Bits
  41. Number of 1 Bits
  42. House Robber
  43. Number of Islands
  44. Reverse Linked List
  45. Course Schedule
  46. Implement Trie (Prefix Tree)
  47. Design Add and Search Words Data Structure
  48. Word Search II
  49. House Robber II
  50. Contains Duplicate
  51. Invert Binary Tree
  52. Kth Smallest Element in a BST
  53.  Lowest Common Ancestor of a Binary Search Tree
  54. Lowest Common Ancestor of a Binary Tree
  55. Product of Array Except Self
  56. Valid Anagram
  57. Meeting Rooms
  58. Meeting Rooms II
  59. Graph Valid Tree
  60. Missing Number
  61. Alien Dictionary
  62. Encode and Decode Strings
  63. Find Median from Data Stream
  64. Longest Increasing Subsequence
  65. Coin Change
  66. Number of Connected Components in an Undirected Graph
  67. Counting Bits
  68. Top K Frequent Elements
  69. Sum of Two Integers
  70. Pacific Atlantic Water Flow
  71. Longest Repeating Character Replacement
  72. Non-overlapping Intervals
  73. Serialize and Deserialize BST
  74. Subtree of Another Tree
  75. Palindromic Substrings
  76. Longest Common Subsequence


 1. Two Sum

This code looks through a list to find two different numbers that add up to a specific target number. It does this by using two loops. The first loop starts at the beginning of the list. For each number in the first loop, the second loop looks at the numbers that come after it in the list. If it finds two numbers that add up to the target, it gives back their positions in the list.

Time Complexity: O(n^2)

This is because for each element in the list (and there are 'n' elements), we are potentially looking at every other element in the list to find a match (which in the worst case is 'n-1' other elements), resulting in 'n' times 'n-1' operations.

Space complexity: O(1)

This code only uses a fixed amount of extra space (for the indices), no matter how big the list gets.

  • Time Complexity: O(n + d) where n is the length of the input string and d is the number of characters in the input string alphabet. 
  • Space Complexity: O(d)

Counting Valleys - Hackerrank Solution

 Check out the counting valleys question here: Hackerrank question

The picturization of the problem:

Suppose the input is: UDDDUDUU

Then, 

Answer: Valley level is 1. Because hiker stepped this way only.

To solve this problem:

Initially, assumed U = 1, D = -1 & altitude=0

Then, iterated till total steps-1. Whenever altitude(height) that is sea level is 0 & the last step is 'U" I have incremented the valley by 1 (because valley level is considered only when hiker's last step is 'U" & at the sea level).

When all the elements are traversed it returned the final valley's value that's our final result.

Solution:

def countingValleys(steps, path):
    # Write your code here
    
    altitude = 0
    valley = 0
    dict = {
        "U": 1,
        "D": -1
    }

    for eachstep in range(steps):
        altitude += dict[path[eachstep]] # calculating hiker's each step

        if altitude == 0 and path[eachstep] == "U":
            valley += 1

    return valley

Sales by Match -Hackerrank solution

Check out the question here - Sales by Match


def sockMerchant(n, ar):

    pairs = 0

    for element in set(ar):
        pairs += ar.count(element) // 2
    
    return pairs

if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')

    n = int(input().strip())

    ar = list(map(int, input().rstrip().split()))

    result = sockMerchant(n, ar)

    fptr.write(str(result) + '\n')

    fptr.close()