---
# System prepended metadata

title: Leetcode

---

# Leetcode

Practice Leetcode - https://leetcode.com/problemset/all/

IMPORTANT - https://www.practicepython.org/


# OOP

Classes - blueprint to make objects
Objects - collection of instance variables and methods

```
public class Animal {
    String name
    String sound
    
    constructor(name, sound) {
        this.name = name
        this.sound = sound
    }
    
    function move();
    function reverseMove();
}

dog makes X sound
cat makes Y sound
lion makes Z sound 


dog = new Animal("leo", "X");
cat = new Animal();
lion = new Animal();
```

Python code -> 
https://meet.google.com/qhg-kgtc-zfy


Four principles of OOP: 

- Encapsulation 
- Polymorphism 
- Inheritance
- Abstraction 
    
    
CODE 

```
# Online Python compiler (interpreter) to run Python online.
# Write Python 3 code in this online editor and run it.

class House:
    price = 1000
    __newVar = "newVar String"
    def __init__(self, name):
        self.wall = 1
        self.name = name
    
    def bedroom(self):
        print("Welcome to bedroom")
        
    def reveal(self): 
        return self.__newVar
        
    def revealNew(self):
        print(self.name)
        return self.reveal();

    
newHouseObj = House("Utkarsh's Home")
print(newHouseObj.wall)
print(newHouseObj.revealNew())

house2 = House("Fariha ")
print(house2.revealNew())

```
    
```
from abc import ABC, abstractmethod
# ABC - Abstract Base Class
#abstract class
class Polygon(ABC): 
    @abstractmethod
    # abstract method 
    def noofsides(self): 
        pass
    def xyz(self):
        print("new")
        pass
  
class Triangle(Polygon): 
    # overriding abstract method 
    def noofsides(self): 
        print("I have 3 sides") 
  
class Pentagon(Polygon): 
    # overriding abstract method 
    def noofsides(self): 
        print("I have 5 sides") 
  
class Hexagon(Polygon): 
    # overriding abstract method 
    def noofsides(self): 
        print("I have 6 sides") 
        
R = Triangle() 
R.noofsides()

H = Hexagon() 
H.noofsides() 
  
P = Pentagon() 
P.noofsides() 

print("R xyz - ")
R.xyz()
print("H xyz - ")
H.xyz()
print("P xyz - ")
P.xyz()


# def x(a):
#     return a
    
# def y():
#     pass

# def z():
#     print("Imdsdf")
    

# old = z()
# newInt = x(5)
# print(old)
# print(newInt)


    
    
```
    
    
Links to check:

OOP 

- https://medium.com/better-programming/python-for-beginners-object-oriented-programming-3b231bb3dd49
- https://medium.com/faun/object-oriented-programming-part-1-c5ad590892ca#:~:text=OOP%20is%20divided%20into%20six,polymorphism%2C%20abstractions%2C%20and%20encapsulations.
- https://www.freecodecamp.org/news/java-object-oriented-programming-system-principles-oops-concepts-for-beginners/
- https://realpython.com/python3-object-oriented-programming/
- 