Saturday, 1 April 2017

Hackerrank Solution For Day 7: Arrays

Problem:- Write a Hackerrank Solution For Day 7: Arrays or Hacker Rank Solution Program In C++ For " Day 7: Arrays " or Hackerrank 30 days of code Java Solution: Day 7: Arrays solution or Hackerrank solution for 30 Days of Code Challenges.

Hacker Rank Solution For Day 7: Arrays

Logic:- This is a very simple problem, here we need to only reverse the array and print the element of the array. As we know that array index starts with zero to n-1. here we just reverse the array by first print the array last index than second last index like n, n-1, n-2,..................... up to (greater or equal) 0 (Zero),

Example:- suppose array with 5 elements is 10, 20, 30, 40, 50 and index of the array is 0, 1, 2, 3, 4 so so first print index 4 and element 50 then index 3 and element 40 and so on up to index 0 and element 10. Check the below picture its shows how exactly array is printing the element in reverse order.

Hacker rank Solution For Day 7: Arrays

All solution provided here are in C++ (CPP) if you want these solutions in C, and Java comments below or sends a mail with your query like " day n solution in C / C++ / Java. If you want to 30 days solution (All previous solution from day 0 ) from Day 0 please check the below link. You can also find more program in below of this post. Check the below solution with the full explanation (explanation in simple language).

2. Hackerrank Solution For Day 3: Intro to Conditional Statements 

3. Hackerrank Solution For Day 4: Class vs. Instance

5. Hacker Rank Solution For Day 5: Loops

6. Hackerrank Solution For Day 6: Let's Review


Copy the colored code and paste it into hacker rank editor. If you have any query feel free to share with me, and if you like my work please share, comments and subscribe this will help you update all about new post this Article.

Submit Your Solution Here:- Click Here

Solution:-

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>

using namespace std;

int main()
{

 int n;
 cin >> n;

 vector<int> arr(n);

 for(int arr_i = 0;arr_i < n;arr_i++)
{
       cin >> arr[arr_i];
}

for(int arr_i = n-1;arr_i >= 0;arr_i--)
{
       cout << arr[arr_i]<<" ";
}
    return 0;
}

Output:-

Hackerrank Solution For Day 7: Arrays


You May Also Like:-





5. Hackerrank Solution For Day 12: Inheritance

6. Hackerrank Solution For Day 13: Abstract Classes

7. Hackerrank Solution For Day 14: Scope

8. Hackerrank Solution For Day 15: Linked List

9. Hackerrank Solution For Day 16: Exceptions - String to Integer

10. Hackerrank Solution For Day 17: More Exceptions

No comments:
Write comments

Recommended Posts × +