Given an integer N, the task is to check if it is possible to make N prime by deleting any single digit from N.
Input: N = 610
Deleting 0 from 610, we get 61 which is prime.
Input: N = 68
Approach: The idea is to convert N to a string. Now iterate for every digit of string and Delete character at index i from string and then convert the string after deleting character at index i to an integer, Now check if this integer is a prime, then return true. Otherwise, finally return false.
Below is the implementation of the above approach:
Time Complexity: O(D)
Auxiliary Space: O(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.
- Count of N-digit numbers having digit XOR as single digit
- Check whether a number can be expressed as a product of single digit numbers
- Check if elements of array can be made equal by multiplying given prime numbers
- Shortest path to reach one prime to other by changing single digit at a time
- Min steps to convert N-digit prime number into another by replacing a digit in each step
- Check if a prime number can be expressed as sum of two Prime Numbers
- Check whether the number can be made perfect square after adding 1
- Check if X and Y can be made zero by using given operation any number of times
- Check if given array can be made 0 with given operations performed any number of times
- Check whether the number can be made perfect square after adding K
- Check whether the number can be made palindromic after adding K
- Maximize the size of array by deleting exactly k sub-arrays to make array prime
- Find all numbers between range L to R such that sum of digit and sum of square of digit is prime
- Queries to check whether all the elements can be made positive by flipping signs exactly K times
- Check if all elements of the given array can be made 0 by decrementing value in pairs
- Check if N and M can be made equal by increasing N by A and decreasing M by B
- Check whether an Array can be made 0 by splitting and merging repeatedly
- Check if given intervals can be made non-overlapping by adding/subtracting some X
- Check if all elements of a Circular Array can be made equal by increments of adjacent pairs
- Finding n-th number made of prime digits (2, 3, 5 and 7) only
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.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.
Improved By : Rajput-Ji