₦airaland Forum

Welcome, Guest: Register • Login • With Google • Trending • Recent • New

Stats: 3,347,246 members, 8,527,329 topics. Date: Monday, 30 November 2026 at 12:52 PM

Toggle theme

Real Programmers Only Here - Programming - Nairaland

Nairaland Forum › Science/Technology › Programming › Real Programmers Only Here (410 Views)

1 Reply (Go Down)

Real Programmers Only Here by Suicideboy(op): 3:12am On Jul 28, 2025
You are given an integer n which represents an array nums containing the numbers from 1 to n in order. Additionally, you are given a 2D array conflictingPairs, where conflictingPairs[i] = [a, b] indicates that a and b form a conflicting pair.

Remove exactly one element from conflictingPairs. Afterward, count the number of

of nums which do not contain both a and b for any remaining conflicting pair [a, b].

Return the maximum number of subarrays possible after removing exactly one conflicting pair.



Example 1:

Input: n = 4, conflictingPairs = [[2,3],[1,4]]

Output: 9

Explanation:
Remove [2, 3] from conflictingPairs. Now, conflictingPairs = [[1, 4]].
There are 9 subarrays in nums where [1, 4] do not appear together. They are [1], [2], [3], [4], [1, 2], [2, 3], [3, 4], [1, 2, 3] and [2, 3, 4].
The maximum number of subarrays we can achieve after removing one element from conflictingPairs is 9.

Example 2:

Input: n = 5, conflictingPairs = [[1,2],[2,5],[3,5]]

Output: 12

Explanation:
Remove [1, 2] from conflictingPairs. Now, conflictingPairs = [[2, 5], [3, 5]].
There are 12 subarrays in nums where [2, 5] and [3, 5] do not appear together.
The maximum number of subarrays we can achieve after removing one element from conflictingPairs is 12.

Constraints:
2 <= n <= 105
1 <= conflictingPairs.length <= 2 * n
conflictingPairs[i].length == 2
1 <= conflictingPairs[i][j] <= n
conflictingPairs[i][0] != conflictingPairs[i][1]

You should be able to solve this.
Re: Real Programmers Only Here by ekrizz(m): 7:12pm On Jul 30, 2025
Is this on Leetcode? This is an algorithm question. I solve algorithm problems with Java on Leetcode, but I'm a NodeJS backend engineer
Re: Real Programmers Only Here by parkervero(m): 7:23pm On Jul 30, 2025
This is definitely not leetcode medium.

I don't like DSA questions.
Re: Real Programmers Only Here by Suicideboy(op): 8:21am On Sep 06, 2025
No programmers here


Na brogrammers day here


Oya Seun come and run this one grin
1 Reply

Let us see the real programmers. Not Every Time Here Frontend, Backend, React. • Good Programmers Needed, Good Programmers Only • E-commerce Startup Company (interested Programmers Only) • 2 • 3 • 4

Seeking Advice On Learning Java And Becoming A Backend Developer • Please Who Has These Ebooks To Learn Python • I Need Suggestions On How To Use Kubernetes To Deploy An App