Please read the new rule regarding the restriction on the use of AI tools. ×

bondchi's blog

By bondchi, history, 2 years ago, In English

can someone please give a solution to this problem[problem:978A][user:DessertRommet]

  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
»
2 years ago, # |
Rev. 3   Vote: I like it +1 Vote: I do not like it

Play with the indexes this time, store the last index of each element either in a map data structure, or an array will work too as array elements are from 1 to 1000.

then create a list/array/vector of the answer and store all the last index in it. Then sort the list, as the index are in increasing order.

print the size and print the element with respective index.

Like this (pseudo code) ->

int arr[n]; // our input array
int lastIndex[1001]= {0}; // array to store last index of the elements as they will not exceed 1000.

for(int i=0; i<n; i++) lastIndex[arr[i]] = i;

vector<int> ans //create an answer vector, similar as list in java

for(int i=0; i<n; i++) ans.push_back(lastIndex[arr[i]]); // store the last index of each element

sort(ans.begin(), ans.end()); //sort the answer so that the element be in order as the index of element are always in increasing order

print ans.size()  //size of the ans array will be the size;

for(int i=0; i<ans.size(); i++) print arr[ans[i]] // print the array with the index we've sorted

check the submission if needed -> 172281151

  • »
    »
    2 years ago, # ^ |
      Vote: I like it -13 Vote: I do not like it

    I like how your pseudocode is very descriptive. +1