HackerRank C++ Variable Sized Arrays




It is just like jagged array. and in this problem for every row there variable sized array



  1. #include <iostream>
  2. #include <cstdio>
  3. using namespace std;
  4. int main()
  5. {
  6. int n,q;
  7. cin>>n>>q;
  8. int** seq=new int* [n];
  9. for(int i=0;i<n;i++)
  10. {
  11. int a;
  12. cin>>a;
  13. int* b=new int [a];
  14. for(int j=0;j<a;j++)
  15. {
  16. int e;
  17. cin>>e;
  18. b[j]=e;
  19. }
  20. *(seq+i)=b;
  21. }
  22. for(int i=0;i<q;i++)
  23. {
  24. int r,s;
  25. cin>>r>>s;
  26. cout<<seq[r][s]<<endl;
  27. }
  28. }




codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube