FastPrepCount Increasing Triplets
Problems/Count Increasing Triplets

Count Increasing Triplets

Salesforce logoSalesforce● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: In the first technical round of a Salesforce MTS loop in Hyderabad, the second coding question asked for the number of index triplets i < j < k whose values strictly increase.

The post gives no examples or limits. Here the array has up to 3000 values between -10^9 and 10^9. Triplets are counted by index. The answer is returned as a 64-bit integer because it can pass 2^31 - 1.

Our version is about 95% the same as the reported question.

Given an array of integers arr, return the number of index triplets (i, j, k) such that i < j < k and arr[i] < arr[j] < arr[k].

Triplets are counted by their indices, so equal values at different positions can form different triplets. The comparisons are strict: two equal values can never be next to each other in a triplet. If no such triplet exists, return 0.

Function

countIncreasingTriplets(arr: int[]) → long

Examples

Example 1

arr = [1,2,3,4]return = 4

Any three of the four values, kept in their order, are increasing. There are 4 ways to choose three of them: (1, 2, 3), (1, 2, 4), (1, 3, 4) and (2, 3, 4).

Example 2

arr = [4,1,3,2,5]return = 2

The value 5 is last and larger than everything, so it is the third value of every triplet here. Before it, the increasing pairs are (1, 3) and (1, 2). So the triplets are (1, 3, 5) and (1, 2, 5), and the answer is 2.

Example 3

arr = [5,5,5,6]return = 0

A triplet needs a strictly increasing middle step. Every triplet here starts with two copies of 5, and 5 < 5 is false, so the answer is 0.

Constraints

  • 1 <= arr.length <= 3000
  • -10^9 <= arr[i] <= 10^9
  • The answer can be larger than 2^31 - 1.

More Salesforce Onsite Interview questions

  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Reverse a Sublist of a Linked ListONSITE INTERVIEW · Seen Nov 2026
  • Rotting OrangesONSITE INTERVIEW · Seen Nov 2026
  • 3Sum SmallerONSITE INTERVIEW · Seen Nov 2026
  • Count Zero Request ServersONSITE INTERVIEW · Seen Nov 2026
  • Construct a Tree from Level-Order and Inorder TraversalsONSITE INTERVIEW · Seen Sep 2026
  • Maximize Monsters DefeatedONSITE INTERVIEW · Seen Sep 2026
  • Flatten Nested Map Paths with a StackONSITE INTERVIEW · Seen Sep 2026
  • LFU CacheONSITE INTERVIEW · Seen Sep 2026
  • Kth Largest Element in an ArrayONSITE INTERVIEW · Seen Sep 2026

Similar questions at other companies

  • Customer Bootstrap APIDoorDash · PHONE SCREEN · ONSITE INTERVIEWDoorDash interview questions
  • Count Subsets With a Target SumSafe Security · ONSITE INTERVIEW
  • Merge Overlapping IntervalsAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
  • Search a Row- and Column-Sorted MatrixByteDance · ONSITE INTERVIEWByteDance interview questions
  • First and Last Target Position in a Mountain ArrayGoogle · ONSITE INTERVIEWGoogle interview questions
  • Shortest Window with Required CountsOracle · ONSITE INTERVIEWOracle interview questions
  • Filter, Sort, and Deduplicate Scheduled TasksRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • Retrieve Vectors by Cosine SimilarityHarvey · ONSITE INTERVIEWHarvey interview questions
  • Round-Robin Iterator over IteratorsBridge · ONSITE INTERVIEWBridge interview questions
  • Propagating Fraud DetectorAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions

Salesforce interview experiences

  • Salesforce Infrastructure SWE OA and Onsite: 1 Experience
  • Salesforce Experienced Backend SWE First Round: 1 Experience
All Salesforce interview questionsSee Salesforce hiring insights
Saved
class Solution {
    public long countIncreasingTriplets(int[] arr) {
        // Write your code here.
    }
}
Checking account…