DEV Community

Mukilan Palanichamy
Mukilan Palanichamy

Posted on

My journey in competitive programming

1. N-Queens II:

Unlike the classic N-Queens problem where we return all valid configurations of the board, in N-Queens II, we are only interested in returning the count of distinct solutions for placing n queens on an n x n chessboard.

Important Points:

  1. The constraints and rules are the same: no two queens can threaten each other.
  2. Use backtracking to check all valid arrangements row by row.
  3. Only count the number of valid configurations, instead of storing all configurations.

Image description

2. 3Sum Closest:

For any given integer array nums and any given target, find three integers from nums such that their sum is closest to target. Return the sum of the three integers. You may assume each input would have exactly one solution.

Important Points:

  1. This problem is an extension of the 3Sum problem, except here we are not looking for all triplets that sum to zero but for the triplet that is closest to a given target.
  2. Sorting the array makes finding triplets less complicated and avoids duplication checks.
  3. Use a two-pointer approach for efficiency.

Image description

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay