P

@praveen11

Maximum Sum Subarray

C++
9 months ago
#include <iostream> #include <vector> using namespace std; int main() { vector<int> v={-2, 1, -3, 4, -1, 2, 1, -5, 4}; int start=-1, end=-1, temp=-1, sum=0, maxSum=-1; for(int i=0; i<v.size(); i++){ if(sum==0) temp=i; sum+=v[i];

Detect Cycle in undirected graph

C++
10 months ago
#include <iostream> #include <vector> #include <queue> using namespace std; class Solution { private: bool detectCycle(int start, vector<vector<int>>& adj, vector<int>& vis) { queue<pair<int, int>> q; vis[start] = 1;

BFS traversal Graph

C++
10 months ago
#include <iostream> #include <vector> #include <queue> #include <algorithm> using namespace std; vector<int> bfs(int start, int n, vector<int> adj[]){ vector<int> bfsV; vector<int> vis(n,0); queue<int> q;

Traversal, Length of LinkedList

C++
10 months ago
#include <iostream> #include <vector> using namespace std; class Node{ public: int data; Node* next; public: Node(int data1){

array and it's operations in JS

NodeJS
2 years ago
const arr = [1,2,3,4,5,6,7]; arr.push(8); console.log(arr); arr.pop(); console.log(arr); arr.shift(); console.log(arr); arr.splice(2); console.log(arr);

rest operator

NodeJS
2 years ago
const func = (...arr) => console.log(arr); func(1,2,3,4,5); const app = (a,...arr) => console.log(a,arr); app(1,2,3,4,5,6);

destructing in JS

NodeJS
2 years ago
// object destructing details = { name : 'praveen', id : 1, age : '22' }; const {name,age} = details;

spread operator

NodeJS
2 years ago
a = { name:'praveen', id:1 } b = {...a, age:22 } console.log(b['name'])

JS ES7 classes

NodeJS
2 years ago
class A{ name = 'praveen'; printName = () => console.log(this.name); } class B extends A{ name = 'praveen kumar'; age = 22; printDetails = () => console.log(this.name + this.age); }

maximum of the given array after converting into non-decreasing array

C++
3 years ago
#include <iostream> using namespace std; int main() { int t; cin>>t; while(t--){ int n; cin>>n; int a[n]; for(int i=0;i<n;i++){

subarrays of an array

C++
3 years ago
#include <iostream> #include <vector> using namespace std; int main() { int n; cin>>n; int a[n]; for(int i=0;i<n;i++){ cin>>a[i]; }

amazon sde 1

C++
3 years ago
#include <iostream> #include <algorithm> using namespace std; int main() { int n; cin>>n; int a[n]; for(int i=0;i<n;i++){ cin>>a[i]; }

Amazon interview question 2

Python
3 years ago
s1=input() s2=input() l=[0]*26 for i in s1: l[ord(i)-97]+=1 #l[i]=a l[97-97]=1 for i in s2: l[ord(i)-97]+=1 flag=0 for i in l: if(i%2!=0):

Amazon interview question 2

Python
3 years ago
s1=input() s2=input() l=[0]*26 for i in s1: l[ord(i)-97]+=1 #l[i]=a l[97-97]=1 for i in s2: l[ord(i)-97]+=1 flag=0 for i in l: if(i%2!=0):

Amazon interview question 1

C++
3 years ago
#include<iostream> #include<vector> #include<algorithm> using namespace std; int main(){ int n=9; int a[]={-5,2,-7,-2,8,4,6,1,3}; // sort(a,a+n); for(int i=0;i<n;i++){ for(int j=1;j<n;j++){

uppercase to lowercase

C++
3 years ago
#include <iostream> using namespace std; int main() { string s="PraVeEn"; cout<<s<<"\n"; for(int i=0;i<s.size();i++){ s[i]=tolower(s[i]); } cout<<s<<"\n";

print strings with matching character occurances

C++
3 years ago
#include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; int check(string s,int count,char ch){ int res=0; for(int i=0;i<s.length();i++){ if(s[i]==ch)

subarray with sum k

C++
3 years ago
#include <iostream> using namespace std; int main() { int n,k; cin>>n>>k; int a[n]; for(int i=0;i<n;i++){ cin>>a[i]; } int sum=a[0],start=0,i;

frequency of words in a text

C++
3 years ago
#include <iostream> #include <string> #include <sstream> #include <map> using namespace std; int main() { string str; getline(cin,str); map<string,int> mp; stringstream s(str);

linear sort for array with 1to N elements

C++
3 years ago
#include <iostream> using namespace std; int main() { int a[]={1,4,5,3,2}; for(int i=0;i<5;){ if(a[i]!=i+1) swap(a[i],a[a[i]-1]); else i++; }