Posts

Showing posts from July, 2024

week2 DSA 05/04, prefix, frequency Array

Image
problem statement: https://leetcode.com/problems/find-the-highest-altitude/description/ //highest altituade class Solutation { public: int largestAltitued (vecotr <int> & gain ) {  int n = gani.size(); vector<int>alt(int,0); for(int i = 1; i<= n; i++;) { alt[i] = alt [i-1] + gain[i-1]; } int max_el = *max_elemenet(alt.begin(), alt.end()); reutrn max_el; } };                                                      **normal way of for loops to count frequency** #include <iostream> #include <string> using namespace std; int main() {     string str = "hello";     int freq[26] = {0}; // Array to store frequency of each letter     // Calculate frequency of each character     for (char c : str) {         freq[c - 'a']++; // Increment the count f...

Week 1, DSA 02/04, array

 PPT:- https://projects.100xdevs.com/tracks/dsa/dsa1 DSA stands for data Structure and Algorithms. Data Structures:  means the way some data is stored for example: we can store data as lists or in a stack or as a tree, All of these are examples of data structures, Algorithms is a set of steps you need to follow to solve some problem. Either the set fo steps is known {example, sorting, DFS etc} or you derive the set of steps using first principles and logical thinking CP stands for Competitive Programing. it is a sport where competitors solve DSA ICPC IOI code jam local contests Array :  Collection of elements of some (any) type is called an array /list int f(int x, vector<int>& nums) { //count of all the pairs (i,x) where A[i] = A[x] and i != x and A is the prefix till x // A =  [nums[0], nums[1], ......, nums[x]] int count = 0; for(int i = 0 ; i< ; i++) { if (nums[i] = nums[x]) { count +=1; } } return count; } int numIdenticalParis(vector<int>...

week 15.1 docker, in project IDX setUp

/* create and setup as mention on step1,2,3,4,5 //if you want to create your won docker project      1) clone your prjoect or write your project      2) Dockerfile  //create a dockerfile in your root of project diricitory and write this inside your dockerfile. inside the Dockerfile mention all commands that will required before start you program. all snippet code mention bellow. a) FROM node:22-alpine   #base image which will retrive by docker registry.           a) FROM node:20   #base image which will retrive by docker registry. b) WORKDIR /app     # working diricitory c) COPY . .      #COPY OVER FILE d) RUN npm install  #run command to build the program d.1) RUN npm run build // e) EXPOSE 8080      # EXPOSE PORT #command to run the application              f)    CMD ["node", "dist/index.js" ]...

form project form scratch full backend-frontend(fullStack)

1. npm init 2. npm install express 3. npm install pg //for postgrace 4. npm install dotenv 5. npm install cors const express = require ( 'express' ); const pg = require ( 'pg' ); const { Pool } = require ( 'pg' ); require ( 'dotenv' ). config (); const cors = require ( 'cors' ) const app = express (); //this is our app or interface of express const port = 8080 ; // Adjust port number as needed const pool = new pg. Pool ({ connectionString: process.env. DATABASE_URL , ssl: { rejectUnauthorized: false } }); // Function to create table if it doesn't exist const createTable = async () => { const client = await pool . connect (); try { const createTableQuery = ` CREATE TABLE IF NOT EXISTS your_table ( id SERIAL PRIMARY KEY, name VARCHAR(100), age INTEGER ); ` ; await client . query ( createTableQuery ); console . log ( "Table 'your_table...