Sort by

recency

|

2216 Discussions

|

  • + 0 comments

    Mobile number

  • + 0 comments

    While maintaining a clear and concise logic, this strategy greatly enhances performance. Learning how to optimize loops and use modular properties in programming challenges is a great exercise. Open this problem on HackerRank by Basement Remodeling Fort Collins this link if you want to investigate or attempt it on your own.

  • + 0 comments

    For JAVA since here the input as well as the output in list so we will the methods of list like a.set(index, value) to replace an element instead of adding new ones, and a.get(index) which will the value on the given index

        public static List<Integer> reverseArray(List<Integer> a) {
            int n = a.size();
            
            // Swaping elements from both ends
            for (int i = 0; i < n / 2; i++) {
                int temp = a.get(i);
                a.set(i, a.get(n - i - 1));
                a.set(n - i - 1, temp);
            }
            
            return a;
        }
    
  • + 1 comment

    c# :

     public static List<int> reverseArray(List<int> a)
        {
            int[] arr = a.ToArray();
            int j = arr.Length-1;
            for(int i = 0; i<arr.Length;i++)
            {
                int change = arr[i];
                
                    if (j > i)
                    {
                        arr[i] = arr[j];
                        arr[j] = change;
                        j--;
                    } 
                
            }
            return arr.ToList();
      }
    
  • + 0 comments

    def reverseArray(a): # Write your code here return list(reversed(a));