Find the Largest Cube formed by Deleting minimum Digits from a number | C # code to implement maximum perfect cube formed after deleting minimum digits ; Returns vector of Pre Processed perfect cubes ; convert the cube to String and push into preProcessedCubes vector ; Utility function for findLargestCube ( ) . Returns the Largest cube number that can be formed ; reverse the preProcessed cubes so that we have the largest cube in the beginning of the vector ; iterate over all cubes ; check if the current digit of the cube matches with that of the number num ; if control reaches here , the its not possible to form a perfect cube ; wrapper for findLargestCubeUtil ( ) ; pre process perfect cubes ; convert number n to String ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static List < String > preProcess ( int n ) { List < String > preProcessedCubes = new List < String > ( ) ; for ( int i = 1 ; i * i * i <= n ; i ++ ) { int iThCube = i * i * i ; String cubeString = String . Join ( " " , iThCube ) ; preProcessedCubes . Add ( cubeString ) ; } return preProcessedCubes ; } static String findLargestCubeUtil ( String num , List < String > preProcessedCubes ) { preProcessedCubes . Reverse ( ) ; int totalCubes = preProcessedCubes . Count ; for ( int i = 0 ; i < totalCubes ; i ++ ) { String currCube = preProcessedCubes [ i ] ; int digitsInCube = currCube . Length ; int index = 0 ; int digitsInNumber = num . Length ; for ( int j = 0 ; j < digitsInNumber ; j ++ ) { if ( num [ j ] == currCube [ index ] ) { index ++ ; } if ( digitsInCube == index ) { return currCube ; } } } return " Not ▁ Possible " ; } static void findLargestCube ( int n ) { List < String > preProcessedCubes = preProcess ( n ) ; String num = String . Join ( " " , n ) ; String ans = findLargestCubeUtil ( num , preProcessedCubes ) ; Console . WriteLine ( " Largest ▁ Cube ▁ that ▁ can ▁ be ▁ formed ▁ from ▁ " + n + " ▁ is ▁ " + ans ) ; } public static void Main ( String [ ] args ) { int n ; n = 4125 ; findLargestCube ( n ) ; n = 876 ; findLargestCube ( n ) ; } }