FastPrepBubble Sort
Problems/Bubble Sort

Bubble Sort

Hartford Financial Services logoHartford Financial Services● EasyFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report asks directly for bubble sort. The rules for sorting an integer array in ascending order, the examples, and the input limits are our choice. Our version is about 90% the same as the reported question.

Implement bubbleSort(nums) using bubble sort to return the integers of nums from smallest to largest.

On each left-to-right pass, compare neighboring elements and swap them when the left value is greater. Continue until the array is sorted. Do not replace bubble sort with a built-in sorting routine or a different sorting algorithm.

You may modify nums in place. Return the resulting sorted array, preserving every occurrence of each input value.

Function

bubbleSort(nums: int[]) → int[]

Examples

Example 1

nums = [5,1,4,2,8]return = [1,2,4,5,8]

Repeated neighboring swaps place the smaller values before the larger values.

Example 2

nums = [3,-1,3,0]return = [-1,0,3,3]

Negative values sort first, and both occurrences of 3 remain.

Example 3

nums = [7]return = [7]

A one-element array is already sorted.

Constraints

  • 1 <= nums.length <= 2000.
  • -10^9 <= nums[i] <= 10^9.

More Hartford Financial Services interview questions

  • Maximum Product SubarrayONSITE INTERVIEW · Seen Sep 2026
  • Swap Adjacent Character PairsONSITE INTERVIEW · Seen Mar 2019
  • Assign Student Grades from CSV MarksONSITE INTERVIEW
  • Second Highest SalaryONSITE INTERVIEW
  • Average Grades per StudentPHONE SCREEN · Seen Aug 2026

Similar questions at other companies

  • Group Transactions by HourAffirm · ONSITE INTERVIEWAffirm interview questions
  • Merge Sorted ArrayDP World · ONSITE INTERVIEW
  • Map and Accumulate Learning QueriesPalantir · ONSITE INTERVIEWPalantir interview questions
  • Meeting RoomsGoldman Sachs · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
  • Sort Products by Aisle With Frozen Items LastInstacart · ONSITE INTERVIEWInstacart interview questions
  • Merge Two Arrays Into Sorted OrderNVIDIA · ONSITE INTERVIEWNVIDIA interview questions
  • Compress Consecutive Integer RangesDocuSign · ONSITE INTERVIEWDocuSign interview questions
  • Filter Anagrams of a TargetMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Rank Transform an ArrayAgoda · ONSITE INTERVIEWAgoda interview questions
  • Sort Documents Left to RightFigma · ONSITE INTERVIEWFigma interview questions
All Hartford Financial Services interview questionsSee Hartford Financial Services hiring insights
Saved
class Solution {
    public int[] bubbleSort(int[] nums) {
        // write your code here
    }
}
Checking account…