Skip to main content

Posts

sort a c++ map using vector extra space logn time

working link here https://www.onlinegdb.com/edit/r1rq9WeF8 /******************************************************************************                               Online C++ Compiler.                Code, Compile, Run and Debug C++ program online. Write your code in this editor and press "Run" button to compile and execute it. *******************************************************************************/ #include <iostream> #include<vector> #include<map> #include<algorithm> using namespace std; template<typename T> bool sort_map(T a,T b) {     return a.second<b.second; } int main() {    map<string,int> newMap;    vector<string> names={"manish","sachin","deepak"};    vector<int> sal={8900000,7100,1232210};    vector <pair<string,int...

checking how many times a value appear in a vector using map and storing each value count in map

/******************************************************************************                               Onnline C++ Compiler.                Code, Compile, Run and Debug C++ program online. Write your code in this editor and press "Run" button to compile and execute it. *******************************************************************************/ #include <iostream> #include<vector> #include<map> using namespace std; void createMap(vector<string> &vec) {     map<string,int> newMap;     for(int i=0;i<vec.size();i++)     {          const string newStr=vec.at(i);         if(newMap.find(newStr.c_str()) != newMap.end())         {              newMap[vec.at(i)]++;      ...

TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. all about TypeScript (main topics about TypeScript )

TypeScript is an open-source programming language developed and maintained by Microsoft. It is a strict syntactical superset of JavaScript, and adds optional static typing to the language. TypeScript is designed for development of large applications and transcompiles to JavaScript. https://en.wikipedia.org/wiki/TypeScript benefits of using typescript 1. it's scalable and fit for large scale projects. 2. run time checking 3. all upcoming features ready to use (javascript) 4. source code compile in mostly es3 or es5 so its run on every browser even on older version of internet explorer. 5. strict type checking which would be not available in javascript . 6. almost all popular libraries support typescript like angular and react. 7.performence is almost the same as javascript or maybe slightly faster than javascript in some cases. POINT 1 creating a class in typescript /LET START WITH A CLASS  class   Emp {    ...

higher order function in javascript a little and neat implementation of higher order function in javascript

working example https://stackblitz.com/edit/js-in2ztw //higher order function is like let  arr1 =[ 11 , 10 , 7 , 8 , 9 , 51 ]; let  arr2 =[ 5 , 3 , 89 , 7 , 6 , 4 ]; let  arr3 =[ 1 , 2 , 3 , 4 , 5 , 6 ]; let  arr4 =[ 5 , 6 , 7 , 8 , 1008 , 11 ]; //get min from first array and max from second const  minMax =(... args )=>{    let  fns = args ;    return   (... args )=>{      const  result = 0 ;      for ( let  i = 0 ; i < fns . length ; i ++)      {        let  func = fns [ i ];       result += func (... args [ i ]);      }      return  result ;    } } const  opArray =[ arr1 , arr2 , arr3 , arr4 ]; const  mathOp =[ Math . mi...

Level Order Tree Traversal (Level order traversal of a tree is breadth first traversal for the tree.)

https://www.geeksforgeeks.org/level-order-tree-traversal/ level order tree Traversal or breadth first traversal for the tree with full example. please note below tree is binary search tree working link=> https://stackblitz.com/edit/typescript-gvv3qk //bfs Level Order Tree Traversal //node class which holds data and left and right child if exits class   TreeNode < T > {     private  data : T ;     private  leftChild : TreeNode < T >= null ;     private  rightChild : TreeNode < T >= null ;     constructor ( _data : T )     {       this . data = _data ;     }    getData ()     {       return   this . data ;     }    setLeft ...

write a program to print all permutations of a given vector

/******************************************************************************                               Online C++ Compiler.                Code, Compile, Run and Debug C++ program online. Write your code in this editor and press "Run" button to compile and execute it. *******************************************************************************/ #include <iostream> #include <algorithm> #include <vector> using namespace std; void displayData(vector<string> &list,int startIndex,int endIndex) {     if(startIndex==endIndex)     {           string str="";          for(int i=0;i<=endIndex;i++)          {              str+=list[i];          }       ...