function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
fiona gentryfiona gentry 

How to use collection

I have a interview question below 

GIVEN:     a string of characters,
 WHEN:     reverse method is invoked
  THEN:    return an array of characters in reversed order for alphanumeric characters only however all other non-alphanumeric characters need to retain their original position
        
        - Implement solution in Apex
public class Class {
    /*
		PROBLEM:
		- User Story: 
			As an organizer, I need to sort in reverse order,
			so that I can help those at the end of the line.

        - Acceptance Criteria:
			GIVEN: 	a string of characters,
            WHEN: 	reverse method is invoked
			THEN:	return an array of characters in reversed order for alphanumeric characters only
					however all other non-alphanumeric characters need to retain their original position
        
        - Implement solution in Apex
      

		VALIDATE SOLUTION:
		// Run anonymous apex
		ASSESSMENT_UtilityClass2.validateSolution();
	
	*/
    
    // SAMPLE:
    // 1. input: 'ABC@HI#J2'
    // 	  output: ['2','J','I','@','H','C','#','B','A']
    
    public static List<String> reverseSpecialString(String input) {
        List<String> resultList = new List<String>();
         // IMPLEMENT
        resultList = input.split('');
        string reversedString='';
        for(integer i=resultList.size()-1;i>=0;i--)
            {
             
            resultList[i]=reversedString+resultList[i];
               
            }
    
       
        
        
         return resultList;
    }
    
    public static void validateSolution() {
        String input = 'ABC@HI#J2';
        List<String> expected = new List<String> {'2','J','I','@','H','C','#','B','A'};
        List<String> actual = reverseSpecialString(input);
        
        System.assertEquals(expected, actual, 'Invalid Results');
    }
}
can any one help solve above for me ,need to validate the code in anonymus apex by writing 
 
Class.validateSolution();

Regards,
Fiona​​​​​​​
SwethaSwetha (Salesforce Developers) 
HI Fiona,
Where exactly are you stuck?