Given two arrays **x[]** and **y[]** where **x[i]** represents the **x** coordinate and **y[i]** represents the corresponding y coordinate of a 2-D point, the task is to print the co-ordinate points in ascending order followed by their frequencies.

**Examples:**

Input:x[] = {1, 2, 1, 1, 1}, y[] = {1, 1, 3, 1, 3}

Output:

1 1 2

1 3 2

2 1 1

Input:x[] = {-1, 2, 1, -1, 2}, y[] = {-1, 1, -3, -1, 3}

Output:

-1 -1 2

1 -3 1

2 1 1

2 3 1

**Approach:** The idea is to use a map having key as pair **(x[i], y[i])** and mapped value as integer frequency of the same point. Key value will store the pair of coordinates and mapped value will store their respective frequencies.

Below is the implementation of the above approach:

## C++

`// C++ implementation of the approach ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to print the coordinates along with ` `// their frequency in ascending order ` `void` `Print(` `int` `x[], ` `int` `y[], ` `int` `n) ` `{ ` ` ` ` ` `// map to store the pairs ` ` ` `// and their frequencies ` ` ` `map<pair<` `int` `, ` `int` `>, ` `int` `> m; ` ` ` ` ` `// Store the coordinates along ` ` ` `// with their frequencies ` ` ` `for` `(` `int` `i = 0; i < n; i++) ` ` ` `m[make_pair(x[i], y[i])]++; ` ` ` ` ` `map<pair<` `int` `, ` `int` `>, ` `int` `>::iterator i; ` ` ` ` ` `for` `(i = m.begin(); i != m.end(); i++) { ` ` ` `cout << (i->first).first << ` `" "` ` ` `<< (i->first).second << ` `" "` ` ` `<< i->second << ` `"\n"` `; ` ` ` `} ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `x[] = { 1, 2, 1, 1, 1 }; ` ` ` `int` `y[] = { 1, 1, 3, 1, 3 }; ` ` ` `int` `n = ` `sizeof` `(x) / ` `sizeof` `(` `int` `); ` ` ` ` ` `Print(x, y, n); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 implementation of the approach ` ` ` `# Function to print the coordinates along with ` `# their frequency in ascending order ` `def` `Print` `(x, y, n): ` ` ` ` ` `# map to store the pairs ` ` ` `# and their frequencies ` ` ` `m ` `=` `dict` `() ` ` ` ` ` `# Store the coordinates along ` ` ` `# with their frequencies ` ` ` `for` `i ` `in` `range` `(n): ` ` ` `m[(x[i], y[i])] ` `=` `m.get((x[i], ` ` ` `y[i]), ` `0` `) ` `+` `1` ` ` ` ` `e ` `=` `sorted` `(m) ` ` ` ` ` `for` `i ` `in` `e: ` ` ` `print` `(i[` `0` `], i[` `1` `], m[i]) ` ` ` `# Driver code ` `x ` `=` `[` `1` `, ` `2` `, ` `1` `, ` `1` `, ` `1` `] ` `y ` `=` `[` `1` `, ` `1` `, ` `3` `, ` `1` `, ` `3` `] ` `n ` `=` `len` `(x) ` ` ` `Print` `(x, y, n) ` ` ` `# This code is contributed ` `# by mohit kumar ` |

*chevron_right*

*filter_none*

**Output:**

1 1 2 1 3 2 2 1 1

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Print number in ascending order which contains 1, 2 and 3 in their digits.
- Print numbers in descending order along with their frequencies
- Print characters having even frequencies in order of occurrence
- Print characters having odd frequencies in order of occurrence
- Print characters having prime frequencies in order of occurrence
- Print characters and their frequencies in order of occurrence using a LinkedHashMap in Java
- Sorting rows of matrix in ascending order followed by columns in descending order
- Sorting rows of matrix in descending order followed by columns in ascending order
- Maximum distance between two points in coordinate plane using Rotating Caliper's Method
- Sort first k values in ascending order and remaining n-k values in descending order
- Sort the given IP addresses in ascending order
- Sorting of Vector of Tuple in C++ (Ascending Order)
- Sort an array of Roman Numerals in ascending order
- Rearrange Odd and Even values in Alternate Fashion in Ascending Order
- Check if it is possible to rearrange rectangles in a non-ascending order of breadths
- Sort an array of string of dates in ascending order
- Python | Sort words of sentence in ascending order
- Sort Matrix in alternating ascending and descending order rowwise
- Sort an Array of dates in ascending order using Custom Comparator
- Generate a Number in Decreasing order of Frequencies of characters of a given String

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.