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
5 changes: 3 additions & 2 deletions C++/h1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// which should be the return value for the function longest pallindrome(char* s).

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

void printSubStr(
Expand Down Expand Up @@ -36,10 +37,10 @@ int longestPalSubstr(string str)
}

for (int k = 3; k <= n; ++k) {
for (int i = 0; i < n - k; ++i) {
for (int i = 0; i < n - k+1; ++i) {
int j = i + k - 1;

if (table[i + 1][j] && str[i] == str[j]) {
if (table[i + 1][j-1] && str[i] == str[j]) {
table[i][j] = true;

if (k > maxLength) {
Expand Down
72 changes: 38 additions & 34 deletions C++/m1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,46 @@
#include <iostream>
using namespace std;

class Solution
bool isPalindrome(string s)
{
public:
bool isPalindrome(string s)
{
int i = 0, j = s.size();
int i = 0, j = s.size() - 1;

while (i < j)
{
if (s[i++] != s[j--])
return false;
}
return true;
}
while (i < j)
{
if (s[i++] != s[j--])
return false;
}
return true;
}

string longestPalindrome(string s)
{
int n = s.size();
if (n == 0)
return "";
string longestPalindrome(string s)
{
int n = s.size();
if (n == 0)
return "";

if (n == 1)
return s;

if (n == 1)
return s;
string result = "";
for (int i = 0; i < n - 1; i++)
{
for (int j = 1; j <= n - i; j++)
{
if (isPalindrome(s.substr(i, j)))
{
if (result.size() < s.substr(i, j).size())
result = s.substr(i, j);
}
}
}
return result;
}

string result = "";
for (int i = 0; i < n - 1; i++)
{
for (int j = 1; j <= n - i; j++)
{
if (isPalindrome(s.substr(i, j)))
{
if (result.size() < j)
result = s.substr(i, j + 1);
}
}
}
return result;
}
};
int main()
{
string s = "babad";
// cout << isPalindrome(s);
cout << longestPalindrome(s);
return 0;
}
78 changes: 48 additions & 30 deletions C++/m2.cpp
Original file line number Diff line number Diff line change
@@ -1,35 +1,53 @@
// find unique triplet such that the sum is 0

#include<iostream>
#include<vector>
#include<set>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

class Solution {
public:
vector<vector<int>> threeSum(vector<int>& nums) {
int target = 0;
sort(nums.begin(), nums.end());
set<vector<int>> s;
vector<vector<int>> output;
for (int i = 0; i < nums.size(); i++){
int j = i + 1;
int k = i+j;
while (j < k) {
int sum = nums[i] + nums[j] + nums[k];
if (sum == target) {
s.insert({nums[i], nums[j], nums[k]});
j++;
} else if (sum < target) {
j++;
} else {
k--;
}
}
}
for(auto triplets : s)
output.push_back(triplets);
return output;
}
};
vector<vector<int>> threeSum(vector<int> &nums)
{
int target = 0;
sort(nums.begin(), nums.end());
set<vector<int>> s;
vector<vector<int>> output;
for (int i = 0; i < nums.size(); i++)
{
int j = i + 1;
int k = nums.size() - 1;
while (j < k)
{
int sum = nums[i] + nums[j] + nums[k];
if (sum == target)
{
s.insert({nums[i], nums[j], nums[k]});
j++;
}
else if (sum < target)
{
j++;
}
else
{
k--;
}
}
}
for (auto triplets : s)
output.push_back(triplets);
return output;
}

int main()
{
vector<int> nums = {-1, 0, 1, 2, -1, -4};
vector<vector<int>> output = threeSum(nums);
for (auto triplets : output)
{
for (auto num : triplets)
cout << num << " ";
cout << endl;
}
return 0;
}
4 changes: 2 additions & 2 deletions C++/s2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ int main(){
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[3] << std :: endl;
return 0;
}
2 changes: 1 addition & 1 deletion JS & TS/four.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let team = [
},
];
const filterBySalary = (peopleArray, threshold = 300) => {
return peopleArray.find((person) => person.salary > threshold);
return peopleArray.filter((person) => person.salary > threshold);
};
const filteredTeam = filterBySalary(team, 300);
console.log(team, filteredTeam);
14 changes: 10 additions & 4 deletions JS & TS/one.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
const printNames = (names) => {
return `We are ${names.toLowerCase()}`;
var getUser = function () {
var user = {
name: "user",
email: "[email protected]",
password: "snvpoj9f"
};
return user;
};
const intro = printNames("krish" + +"bob");
console.log(intro);
var user1 = getUser();
// Print the user1 object
console.log(user1);
3 changes: 3 additions & 0 deletions JS & TS/one.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
type User = {
name: string;
email: string;
password: string;
};

const getUser = (): User => {
Expand All @@ -13,3 +14,5 @@ const getUser = (): User => {
};

const user1 = getUser();
// Print the user1 object
console.log(user1);
2 changes: 1 addition & 1 deletion JS & TS/three.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const team = [
},
];
const hasFriends = (person) => {
return !(person.friends === false);
return !(person.friends === false) && person.friends !== undefined;
};

const jamesHolden = team[3];
Expand Down
5 changes: 5 additions & 0 deletions JS & TS/two.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ const noOfPeopleEarning = (employees) => {
let total = 0;
for (const employee of employees) {
const earns = employee.earns;
// If earns is undefined, it will be false
if (earns === undefined) {
console.log("undefined");
continue;
}
if (earns === false) {
continue;
}
Expand Down
6 changes: 4 additions & 2 deletions Web-Dev/event-propogation/initial.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// Event listener for form submit
document.getElementById("form").addEventListener("submit", function () {
// Prevent the default action of the event which is to submit the form
event.preventDefault(); // Prevents the default action of the event which is to submit the form
signInWithUserNameAndPassword();
});

// Event listener for sign-in button
document
.getElementById("signin-button")
.addEventListener("click", function (event) {
event.preventDefault();
.addEventListener("onClick", function (event) {
event.preventDefault(); // Prevents the default action of the event which is to submit the form
console.log(userName, password);
});

Expand Down