Posts

Hackerrrank best solution for Designer PDF viewer

Here is a simple and easiest way to implement this function in c++:  int   designerPdfViewer ( vector < int >   h ,   string   word )   {      vector < int >   height ;      for ( int   i = 0 ;   i < word . length ();   i ++){          char   ch =   word . at ( i );          int   l = ch - 97 ;          cout << l << " " ;          height . push_back ( h [ l ]);      }      int   max =* max_element ( height . begin (),   height . end ());      return   max * word . length (); }

Varibale sized arrays in c++

 Here is a simple code to create variable sized arrays in c++ : (the code is from hackerrank problems) #include   < cmath > #include   < cstdio > #include   < vector > #include   < iostream > #include   < algorithm > using   namespace  std ; int  main ()   {      /* Enter your code here. Read input from STDIN. Print output to STDOUT */          int  n ,  q ;     vector < vector < int >>  vectors ;          cin >> n ;     cin >> q ;      for ( int  i = 0 ; i < n ; i ++){          int  size ;         cin >> size ;        ...