Learn DSADSAContests
coding75 logo
LeetCode POTDPOTDSheets
coding75 Pro
coding75 logo
Dashboard
Learn DSA
Course RoadmapFlow
DSA Topic TreeNew πŸš€
Contest SolutionsPractice
Practice Sheets
MasterclassesLive πŸ‘¨πŸ»β€πŸ’»

coding75 ProPRO

Live Classes & Placement Guidance

coding75 logo

The premier developer platform for mastering Data Structures & Algorithms, exploring contest editorials, building ATS-ready resumes, and accelerating your tech career.

Connect & Community

DSA & Contests

  • Learn DSA
  • Contest Solutions
  • LeetCode POTDDaily
  • Practice Sheets
  • MasterclassesSoon

Interview Prep

  • Portfolio Projects
  • CS Fundamentals
  • System DesignSoon
  • Interview ExperiencesSoon
  • Mock InterviewsSoon

Career & Pro

  • Jobs & Internships
  • Resume BuilderATS
  • coding75 Pro
  • Submit Feedback
Β© 2026coding75β€’crackDSAβ„’β€’Maa Lalita Edtech Private Limited. All Rights Reserved.
Privacy PolicyTerms & ConditionsContact Support
Registered Office: Kanpur 208021β€’Regional Office: Indiranagar, Bangalore, 560008
Maa Lalita Edtech Private Limited
Contests/LeetCode/Weekly Contest 500/3918. Sum of Primes Between Number and Its Reverse
PrevNext
LeetCodeLeetCode
Medium
Weekly Contest 500

3918. Sum of Primes Between Number and Its Reverse

ArrayMathMiscellaneous
Loading...
Solve on LeetCode

Problem Statement

Official algorithmic problem description and constraints.

Open on LeetCode

You are given an integer n.

Let r be the integer formed by reversing the digits of n.

Return the sum of all prime numbers between min(n, r) and max(n, r), inclusive.

 

Example 1:

Input: n = 13

Output: 132

Explanation:

  • The reverse of 13 is 31. Thus, the range is [13, 31].
  • The prime numbers in this range are 13, 17, 19, 23, 29, and 31.
  • The sum of these prime numbers is 13 + 17 + 19 + 23 + 29 + 31 = 132.

Example 2:

Input: n = 10

Output: 17

Explanation:

  • The reverse of 10 is 1. Thus, the range is [1, 10].
  • The prime numbers in this range are 2, 3, 5, and 7.
  • The sum of these prime numbers is 2 + 3 + 5 + 7 = 17.

Example 3:

Input: n = 8

Output: 0

Explanation:

  • The reverse of 8 is 8. Thus, the range is [8, 8].
  • There are no prime numbers in this range, so the sum is 0.

 

Constraints:

  • 1 <= n <= 1000


Solutions & Walkthrough

Detailed video explanations, mathematical intuition, and clean C++ implementation code.

Connecting secure classroom stream...
Back to Weekly Contest 500
Previous ProblemNext Problem