A

@Adarsh1999

Median of Two Sorted Arrays

C++
1 year ago
#include <algorithm> #include <iostream> #include <vector> #include <map> int main() { std::vector<int> a = {1,8,5,4}; std::vector<int> b = {3,6,7,9}; std::vector<int> c = {3,6,7,9,2};

Duplicate elements remove

C++
1 year ago
#include <iostream> #include <vector> #include <string> int main() { std::string a = "adarsh"; std::vector<int> frq(128, 0); for(char i=0; a[i]!='\0'; i++) { frq[a[i]]++;

Usaing hash

C++
1 year ago
#include <iostream> #include <map> #include <string> #include <cstdint> // For uint32_t namespace pki { typedef uint32_t hash_t; // Simulating a function that generates a hash from a certificate subject hash_t getCertSubjectHash(const

Reference in c++

C++
1 year ago
#include <iostream> #include <string> // Function declarations void function1(std::string& str); void function2(std::string& str); void function3(std::string& str); int main() { std::string myString = "Hello";

Map types

C++
1 year ago
Summary of Map Types: Map Type Unique Keys Key Order Internal Structure Time Complexity (average) std::map Yes Sorted (ascending) Binary Search Tree O(log n) std::multimap No So

Map imp code and rules

C++
1 year ago
#include <iostream> #include <vector> #include <map> #include <string> int main() { // key value std::map<std::string, int> student; std::map<int, std::vector<std::string>> sd; std::string ip;

map advance all cases covered

C++
1 year ago
#include <iostream> #include <map> int main() { // Declare a map that maps strings (names) to integers (ages) std::map<std::string, int> ageMap; // 1. Element Access: ageMap["Alice"] = 25; // Using operator[] ageMap["Bob"] = 30

string with vector ascii

C++
1 year ago
#include <iostream> #include <vector> #include <string> int main() { std::string s = "ADARSH"; // Example string std::vector<int> charIndex(128, -1); // 128 for ASCII characters, initialized to -1 // Iterate over the string and store

string with vector ascii

C++
1 year ago
#include <iostream> #include <vector> #include <string> int main() { std::string s = "ADARSH"; // Example string std::vector<int> charIndex(128, -1); // 128 for ASCII characters, initialized to -1 // Iterate over the string and store

linkedlist add to list

C++
1 year ago
#include <iostream> class Node { public: int data; Node* next; // Constructor to initialize a new node Node(int val) { data = val;

Sum of 2

C++
1 year ago
#include <iostream> #include <vector> class sol{ public: std::vector<int> tw(std::vector<int>& nums, int target); }; std::vector<int> sol::tw(std::vector<int>& nums, int target){ std::vector<int> val;

Oops concept difference

C++
1 year ago
Inheritance When one object acquires all the properties and behaviours of parent object i.e. known as inheritance. It provides code reusability. It is used to achieve runtime polymorphism. Sub class - Subclass or Derived Class refers to a cla

Ooops basic

C++
1 year ago
#include <iostream> class Rectangle{ private: int length; int width; public: Rectangle(int l, int w) : length(l), width(w){};

Abstraction & Encapsulation diff

C++
1 year ago
/* Abstraction: Definition: As discussed earlier, abstraction is the concept of hiding unnecessary details and exposing only the relevant information or functionality to the user. Goal: To simplify complexity by focusing on essential features and l

Dynamic Polymorphism

C++
1 year ago
#include <iostream> #include <memory> class Animal { public: virtual void speak() const { std::cout << "Animal speaks" << std::endl; } virtual ~Animal() = default;

vector string

C++
1 year ago
#include <iostream> #include <string> #include <vector> #include <sstream> class data { public: // Constructor data() { std::cout << "constructor called" << std::endl;

interview prep

C++
1 year ago
#include <iostream> https://www.geeksforgeeks.org/cpp-interview-questions/

Types of constructor

C++
1 year ago
Default Constructor: Definition: A constructor that takes no arguments or all its parameters have default values. Purpose: It initializes objects with default values. Example: cpp Copy code class MyClass { public:

Basics of lambda

C++
1 year ago
#include <iostream> #include <vector> #include <algorithm> int main() { auto add = [](int a, int b) -> int{ return a+b; }; int ret = add(5,8);

New operator

C++
1 year ago
The new operator in C++ is used for dynamic memory allocation. It allocates memory on the heap (free store) and returns a pointer to the beginning of the newly allocated memory block. This is particularly useful when you need to create objects or ar