Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions C++/s1.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
// to find the reverse of a given number

#include<iostream>
#include <iostream>
using namespace std;

int reverse(int x) {
long r=0;
while(x){
r=r*10+x/10;
x=x/10;
int reverse(int x)
{
long r = 0;
while (x)
{
// r=r*10+x/10; // bug
r = r * 10 + x % 10; // solution
x = x / 10;
}
return r;
}

int main(void){
int main(void)
{
cout << reverse(12345) << endl;
}
}
17 changes: 10 additions & 7 deletions C++/s2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
#include <iostream>
#include <vector>

int main(){
std :: vector<int> myVec;
int main()
{
std ::vector<int> myVec;
myVec.push_back(1);
myVec.push_back(2);
myVec.push_back(3);

for(int i=0; i < myVec.size(); i++){
std :: cout << myVec[i] << std :: endl;
for (int i = 0; i < myVec.size(); i++)
{
std ::cout << myVec[i] << std ::endl;
}
std :: cout << "Element at index 3: "<< myVec.at(3) << std::endl;

// std :: cout << "Element at index 3: "<< myVec.at(3) << std::endl; // bug
std ::cout << "Element at index 3: " << myVec.at(2) << std::endl; // solution

return 0;
}
}
18 changes: 12 additions & 6 deletions C++/s3.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
// find the bug in the concept

#include<iostream>
#include <iostream>
using namespace std;

int i = 5;
int j;

int foo(int j) {
for (i=0; i<j; i++){
int foo(int j)
{
for (i = 0; i < j; i++)
{
cout << i << " ";
}
return j;
}

void ineedj(void) {
void ineedj(void)
{
cout << "j is " << j << "\n";
}

main() {
// main() {//bug
int main()
{ // solution
int j;
j = foo(i);
ineedj();
}
return 0;
}
18 changes: 10 additions & 8 deletions C++/s4.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
// random returns a random (positive) integer.
// Random returns a random integer in the range 0 to n-1.

#include<iostream>
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define Random(n) random()%n
#define Random(n) random() % n

int random(){
int random()
{
srand(time(0));
return rand();
}


int main(void){
int i=6, j=7;
int val = Random(j-i+1);
int main(void)
{
int i = 6, j = 7;
// int val = Random(j-i+1);
int val = random() % (j - i + 1);

cout << val << endl;
}
}
12 changes: 6 additions & 6 deletions C++/s5.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include<iostream>
#include <iostream>
using namespace std;


int main(void){
int main(void)
{
string string1 = "Hello";
string string2 = "Horld";

if (string1 == string2)
cout << "Equal";
cout << "Equal";
else
cout << "Not Equal";
}
cout << "Not Equal";
}
30 changes: 24 additions & 6 deletions C++/s6.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
// to find the largest sum of subarray
#include<iostream>
#include <iostream>
using namespace std;

int maxSubArraySum(int a[], int size)
{
int max_so_far = INT_MIN, max_ending_here;

for (int i = 0; i < size; i++) {
// change INT_MIN to 0
int max_so_far = 0;
int max_ending_here = 0;

for (int i = 0; i < size; i++)
{
max_ending_here = max_ending_here + a[i];
if (max_so_far < max_ending_here)
max_so_far = max_ending_here;

if (max_ending_here < 0)

// if (max_ending_here < 0)//bug
if (max_ending_here < max_so_far) // solution
max_ending_here = max_so_far;
}
return max_so_far;
}
// solution
int main()
{
int a[5];
for (int i = 0; i < 4; i++)
{
a[i] = i;
}
a[4] = -2;

int max = maxSubArraySum(a, 5);
cout << max << endl;
return 0;
}
12 changes: 10 additions & 2 deletions JS & TS/four.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ let team = [
},
];
const filterBySalary = (peopleArray, threshold = 300) => {
return peopleArray.find((person) => person.salary > threshold);
// return peopleArray.find((person) => person.salary > threshold);
// pushing all the person with salary > threshold into the list
list = [];
peopleArray.forEach((person) => {
if (person.salary > threshold) {
list.push(person);
}
})
return list;
};
const filteredTeam = filterBySalary(team, 300);
console.log(team, filteredTeam);
console.log(filteredTeam);
3 changes: 2 additions & 1 deletion JS & TS/one.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const printNames = (names) => {
return `We are ${names.toLowerCase()}`;
};
const intro = printNames("krish" + +"bob");
// const intro = printNames("krish" + +"bob");
const intro = printNames("krish" + "bob");
console.log(intro);
5 changes: 4 additions & 1 deletion JS & TS/three.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ const team = [
{
name: "james",
place: "earth",
// james' friends should be defined
},
];
const hasFriends = (person) => {
return !(person.friends === false);
// return !(person.friends === false);
return !(person.friends === undefined);
};

const jamesHolden = team[3];
const jamesHasFriends = hasFriends(jamesHolden);
console.log(jamesHasFriends);

2 changes: 2 additions & 0 deletions JS & TS/two.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const team = [
{
name: "james",
place: "earth",
// james' earns value is not defined
earns: false,
},
];

Expand Down
23 changes: 12 additions & 11 deletions Web-Dev/css-is-awesome/initial.css
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
body {
min-height: 90vh;
background: linear-gradient(90deg, #0c97fa 0%, #16e1f5 100%);
display: grid;
place-items: center;
min-height: 90vh;
background: linear-gradient(90deg, #0c97fa 0%, #16e1f5 100%);
display: grid;
place-items: center;
}

.container {
background: white;
width: 120px;
height: 200px;
padding-inline: 0.3rem;
font-size: 3rem;
border-radius: 0.3rem;
}
background: white;
/* Do not give a fixed width */
/* width: 120px; */
height: 200px;
padding-inline: 0.3rem;
font-size: 3rem;
border-radius: 0.3rem;
}