Posts

Using Generic in TypeScript about types in the Code

Image
# Using Generic in TypeScript about types \<T> in the Code ## Question 1: Here what is this <T> means? ```typescript const addID = <T>(obj: T) => {   let ID = Math.floor(Math.random() * 100);   return ({...obj, ID}); } ``` ## Answer 1: In the code snippet you've provided, `<T>` is a **generic type parameter** in TypeScript. It allows you to write a function that can work with any type of object while still maintaining that object's specific type information. When you use the function `addID`, you can pass in an object of any type, and TypeScript will understand that the returned object will be of the same type as the input, plus the additional `ID` property. Here's a breakdown of how it works: ```typescript const addID = <T>(obj: T) => {   let ID = Math.floor(Math.random() * 100);   return ({...obj, ID}); } ``` - `<T>`: Declares a generic type `T`. - `(obj: T)`: Indicates that the function takes an argument `obj` of type `T`. - `ret

Usage of Common “Header files” in C programming

  Each of these header files serves a specific purpose in a C program: stdio.h : This header file stands for "standard input-output header" and provides functions for input and output operations such as  printf()  and  scanf() . stdlib.h : It stands for "standard library" and provides functions such as memory allocation ( malloc() ,  calloc() ,  free() ), random number generation ( rand() ,  srand() ), and other utility functions. string.h : This header file provides functions for manipulating strings such as  strcpy() ,  strcat() ,  strlen() , etc. conio.h : This header file provides functions mainly for console input and output operations in DOS and Windows environments. Functions like  getch()  and  clrscr()  are included in this header file. However, note that it's not a standard C library and is often not available in many modern compilers or platforms. time.h : This header file provides functions to work with date and time. Functions like  time() ,  ctime(

Easiest way to print `int 128 bit` or`unsigned int 128 bit`

Image
  To print `__int128`, you must use `__int128_t`data type. Because there is no data type named __int128. At least I didn’t find any till now. And You must use “typecasting” every time in assigning value and outputting values. you must use format specifier `%lld` for `__int128_t` and `%llu`for `__uint128_t`. in C++, `std::cout`printing… you must use `static_cast <long long> (var_name)` Code: # include <iostream> int main () { // int 128 bit __int128_t var = ( long long ) -23542342345435 ; // unsigned int 128 bit __uint128_t var2 = ( long long ) 64324234234234 ; // printing in c++ std::cout << "int 128 bit: " << static_cast < long long >(var) << std::endl; // printing in c printf ( "int 128 bit: %lld\n" , ( long long )var); // printing in c++ std::cout << "unsinged int 128 bit: " << static_cast < long long >(var2) << std::endl; // printing in c printf ( "unsinged int 128 bi

Bitwise Operators in C/C++

Image
  Bitwise Operators in C/C++ In C, the following 6 operators are bitwise operators (also known as bit operators as they work at the bit-level). They are used to perform bitwise operations in C. The & (bitwise AND) in C or C++ takes two numbers as operands and does AND on every bit of two numbers. The result of AND is 1 only if both bits are 1. The | (bitwise OR) in C or C++ takes two numbers as operands and does OR on every bit of two numbers. The result of OR is 1 if any of the two bits is 1. The ^ (bitwise XOR) in C or C++ takes two numbers as operands and does XOR on every bit of two numbers. The result of XOR is 1 if the two bits are different. The << (left shift) in C or C++ takes two numbers, the left shifts the bits of the first operand, and the second operand decides the number of places to shift. The >> (right shift) in C or C++ takes two numbers, right shifts the bits of the first operand, and the second operand decides the number of places to shift. The ~ (bi

Enhancing Internet Speed Through CMD Commands

Image
## Enhancing Internet Speed Through CMD Commands To improve your internet connection using cmd, you can leverage several built-in Windows features. These include managing DNS cache, pinging the default gateway, and adjusting TCP settings with the `netsh int tcp` command. When facing a slow internet connection, the usual first step is to restart the device or router. If this doesn't resolve the issue, reaching out to the ISP is the next step. If the problem persists even after contacting the ISP, some users might consider changing their service provider. To potentially avoid these steps, here are some strategies for boosting your internet speed using cmd. ### How to Improve Internet Speed Using CMD? There are numerous built-in Windows commands and tools that can address common issues like slow internet. To utilize these cmd tricks, you don't need to be an expert; just follow the instructions provided. 1. **Test Internet Speed Using CMD Pings to Default Gateway**    You can gauge

Difference between vectors in C++

Image
Difference between vectors in C++ Difference between vectors in C++ In C++, the vector is a dynamic array that can grow in size. The three declarations you’ve provided are different ways to declare a vector, and here’s what each one means: vector<int> result; This declares a vector named result that will store integers ( int ). Initially, it is empty, and its size will grow dynamically as integers are added to it. 2. vector<int> result[10]; This is actually an array of vectors. It declares an array named result with 10 elements , where each element is a vector that can store integers. Each vector in the array can grow independently in size. 3. vector<int> result(nums.size()); This declares a vector named result that will store integers, and it is initialized to have a size equal to nums.size() . Assuming nums is another vector, result will have the same number of elements as nums from the start. In summary: The first declaration is a single vector with a dyna

Array of Strings in C programming

Image
Array of Strings in C programming Size of an array: T he size of the  ss  array is 32 because it's an array of pointers to characters (i.e., strings). In C, the size of a pointer is typically 4 or 8 bytes, depending on the architecture (32-bit or 64-bit). I n your case, it seems like you're running this code on a 64-bit system, where the size of a pointer is 8 bytes. The  ss  array has 3 elements, each of which is a pointer to a string. So, the total size of the  ss  array is 4 *  8 = 32 bytes. This is why  sizeof(ss)  is32. The  sizeof  operator in C returns    the size of the object or type in bytes. Code: #include <stdio.h> #include <stdlib.h> #include <string.h> int main (){         char s[ MAX_NAME ] = "Ashiq" ;     char* ss [] = { "ash" , "che" , "ashiq" , "chester" };     int length = sizeof ( ss ) /sizeof ( ss [ 0 ]);     int sizeofarray = sizeof ( ss );     printf ( "length: %d\n "

Why do priority queue implementations often use a heap?

Image
Let’s delve into why priority queue implementations often use a heap: Efficient Operations: Heaps provide efficient insertion and deletion operations, which are crucial for maintaining the priority queue. A min-heap (where the smallest element is at the root) or a max-heap (where the largest element is at the root) can be used to achieve this efficiency. Heap Properties: A heap is a binary tree with specific properties: In a min-heap, the value of each node is greater than or equal to the values of its children. In a max-heap, the value of each node is less than or equal to the values of its children. These properties ensure that the highest-priority element (according to the heap type) is always at the root. Priority Queue Operations: Insertion: Adding an element to the priority queue involves inserting it into the heap while maintaining the heap properties. Deletion (Extract-Min or Extract-Max): Removing the highest-priority element (root) from the heap. Both of these operations hav

Is a priority queue a subsection of a queue?

Image
A priority queue is indeed a specialized type of queue. Here’s how they relate: Queue: A queue is a linear data structure that follows the FIFO (First-In-First-Out) principle. Elements are added to the back (rear) of the queue and removed from the front (head). It’s like waiting in a line—people who arrive first are served first. Priority Queue: A priority queue is an extension of the basic queue. In a priority queue, each element has an associated priority value. Elements with higher priority values take precedence over those with lower priority values. When removing elements, the one with the highest priority is dequeued first. So, while a priority queue shares some similarities with a regular queue, it introduces the concept of prioritization based on values. Think of it as a queue where certain items get to “jump the line” based on their importance! 🚀 

Whiteboarding Interviews

Image
 ⭕ Whiteboarding interviews are a common way of assessing the technical and non-technical skills of candidates for software development positions. They involve solving a coding problem or designing a system on a whiteboard, either in person or virtually, while explaining your approach and reasoning to the interviewer.  ⭕ Some of the benefits of whiteboarding interviews are that they can test your problem-solving ability, communication skills, and coding proficiency in a realistic scenario. They can also help you demonstrate your creativity, collaboration, and passion for the role. However, some of the drawbacks of whiteboarding interviews are that they can be stressful, artificial, and biased. They can also favor memorization over understanding and overlook other aspects of your skills and experience.  ⭕ If you want to ace a whiteboarding interview, you should practice beforehand, prepare for the interview setting, set objectives and expectations, create a good candidate experience, es

Popular posts from this blog

Whiteboarding Interviews

Version Control with Git: A Beginner’s Guide

Callback function in JavaScript