2025/3 tiktok Interviews | tiktok Question Analysis | tiktok Interviews | tiktok Acreage

tiktok interview experience

2025.March latest tiktok interview experience, let's take a look at it~

Tiktok three rounds first round second round are coding, two questions per round. bq is about a project, followup difficulties encountered in the project. hm interview resume + coding. resume asked infra, coding is dp.

Code

Question 1

Whether the array is ordered under the condition that it is allowed to modify at most one element of the array.
Consider traversing the array from front to back, will encounter elements nums[i] that do not satisfy the ordered condition, i.e., nums[i] < nums[i-1], if i is size-1 i.e., the last element, or the array is already all ordered, return true directly, otherwise the size of nums[i+1] should be considered:

  • If nums[i+1] >= nums[i-1], such as the array 0, 1, 2, [1], 3... in 3 > 2, then i+1 and the elements before it satisfy the conditions of the question, and return true if the latter is ordered;
  • Otherwise, if 3 < 4 in the array 0, 1, 4, [1], 3..., it is sufficient if you change nums[i-1] to nums[i], and then traverse the array from i-2 to determine whether it is ordered.

Time complexity O(n), Space complexity O(1)

reasoning

  1. Iterate through the array to find the first position that violates non-decreasing orderi(i.e.)nums[i] < nums[i-1]).
  2. If i has traversed to the end of the array or to the penultimate element, it means that at most one element is out of order and can be fixed by modifying that element and returning directly to thetrue.
  3. Check if it is possible to modify thenums[i-1]maybenums[i]to fix the array.
  4. from positioniStarts and continues traversing the array backward, checking to see if all elements satisfy non-decreasing order. If any elements are found to be out of order, return thefalse.
  5. If the entire array satisfies non-decreasing order, returntrue.
class Solution.
    def checkPossibility(self, nums): i = 0
        i = 0
        for i in range(1, len(nums)): if nums[i] < nums[i-1]: if i = 0
            if nums[i] < nums[i-1].
                if nums[i] = len(nums) - 1: return True
            if i >= len(nums) - 1: return True

        if nums[i + 1] >= nums[i - 1].
            i += 1
        else: nums[i - 1] = nums[i - 1]: i += 1
            nums[i - 1] = nums[i]
            i = max(0, i-2)

        for i in range(i, len(nums) - 1).
            if nums[i] > nums[i + 1].
                if nums[i] > nums[i + 1]: return False
        if nums[i] > nums[i + 1]: return False

Question 2

Find the node in the tree that has the smallest average distance to other nodes, an edge distance counts as 1 and requires a time complexity of O(n). consultation

reasoning

  1. First, define a flag variablevisited, which is used to mark whether the target node p has been found, with an initial value offalse.
  2. Define an empty stackstack, which is used to store the values of the nodes on the path from the root node to the target node p.
  3. Define a functiongetDisToPar, receives three parameters: the current noderootTarget nodespand a stack for storing pathsstack.
  4. existgetDisToParfunction, first check whether the current node is empty, if it is empty, then directly return.
  5. Adds the value of the current node to the stack.
  6. If the current node is the target node p and has not been previously accessed (visitedbecause offalse), then thevisitedmark sth. astrueand return.
  7. If the target node p has not been found yet, look recursively in the left subtree first.
  8. If it is not found in the left subtree, then recursively look in the right subtree.
  9. If neither the left nor right subtree of the current node finds the target node p, it means that the current node is not on the path of the target node p. Pop it off the stack.
  10. At the end of the function run, the stack stores the values of the nodes on the path from the root node to the target node p.
visited = False
stack = []

def getDisToPar(root, p, stack):
    global visited
    if root is None: return
        return
    # Add node to stack
    stack.append(root.val)
    # If found
    if not visited and root == p.
        visited = True
        if not visited and root == p: visited = True
    # Find left subtree first
    if not visited: getDisToPar(root.left, p, stack)
        getDisToPar(root.left, p, stack)
    # Left subtree not found then right subtree
    if not visited: getDisToPar(root.left, p, stack)
        getDisToPar(root.right, p, stack)
    # If not found, it is not under this node, pop it up
    if not visited: getDisToPar(root.right, p, stack)
        stack.pop()
    return

After our strong interview assistance, OA ghostwriting for hire for masters, candidates through the analysis and communication of these interview questions, the interviewer not only understands the candidate's programming ability, but also sees my clear thinking and effective communication skills in the problem solving process. These not only help to cope with tiktok interview, but also enhance our ability to solve practical programming problems. I wish you all good luck in your interviews!

If you also need our interview assistance services, please Contact Us Now.

author avatar
azn7u2@gmail.com
END
 0
Comment(没有评论)