Coders Packet

Finding the maximum sum lane using C++

By Jayaditya Jakkam

  • Finding the maximum sum lane using Cpp.docx
  • max lane.cpp
  • Given two arrays A and B representing two lanes of a route, from this, we can find the maximum sum route and return back the sum using C++

    Given two arrays A and B representing two lanes of a route, we can start from anywhere and can switch the lane if there is the same value at the same index, from this we can find the maximum sum route and return back the sum in C++ programming.

    In the code, I have defined a function named dis, which is used to find the distance between two iterators.

    In the main code, firstly we take the sizes of the 2 inputs, corresponding values to array 1, while taking values for array 2, I have put the indexes which have the common value in both the arrays in a vector.

    Now we start from index 1st to the 2nd element of the vector (which has index values) and check which lane gives the maximum sum with the help of the disfunction and store the sum in the variable (here res). We have to repeat to find the max sum till we reach the last element of the vector. We also check for the index which is the last element of the vector to the last element of the respective arrays. And keep on adding the sum value to the res value.

    On reaching the end we get the maximum sum of the lane.

    Applications:

    This code can be used by apps that show the distance, games for collecting maximum points.

    The code file is also attached to this report.

    Download Complete Code

    Comments

    No comments yet