programming languages: do hidden variables work in terms of blocks or line by line?

Suppose I have the following code:

declaration of a
declaration of b
..a..b
{
  ..a..b
  declaration of a 
  declaration of b
  ..a
}

In this code {} represents the inner block. the statement represents the binding occurrence and .. represents the applied occurrence.

So my question is whether it is legal to use external scope variables within an internal scope and then re-declare them. If so, how does the external variable hiding system work (it starts working when you see a redeclaration)? Thanks in advance.

functional programming: what kind of grammar could it be?

I'm trying to sort the Grammar into Chomsky's Hierarchy and I can do it for most of my examples, but I'm surprised by the following:

bX -> abY

what kind of grammar would this be, unrestricted grammar, context sensitive grammar, context free grammar, or regular grammar

Thanks for your help

Programming Languages: Can someone in Computing, Cyber ​​Security, or IT help you answer these frequently asked questions about the changing field of online security?

I am composing an essay in English on the discord communities of computing and security and I wanted some honest and legitimate answers on the following topics. Don't be afraid to speak openly in the vernacular or lexicon of your field, these are quite open questions and the more detailed you are with your own experience and work, the better the content for this essay. Thank you!

1.] Before, the most common types of malware were generally Trojans and various other types of viruses derived from your own email on a desktop. Given the time interval since those days, the game has changed. Today, the ways of violating a user's data have changed dramatically. What are the most frequent methods that an average person should know today?

2.] Smartphones today are perhaps the most widespread and integrated mode of personal computers. In what main ways has cybersecurity changed with these devices? How are they easier to violate and how are they more difficult?

3.] Large-scale data breaches, such as notable examples with Sony and Marriott, have compromised confidential user data around the world. What are the risks that users run when registering their information online? How much trust can these data collecting organizations be given and what steps can a user take to protect themselves?

4.] Often, phishing attempts are successful in which a user gives their password and personal information to an attacker. When IT assistance is needed, how can you ensure a user is not working with an infamous attacker?

5.] Third-party software is an extremely common way to infect a user's device with malware. Since applications and software are downloaded by almost anyone on any device, how can a user know that the material they are downloading is safe? What are some checks a person can do on their devices to make sure they are free of malware?

dynamic programming: definition of an algorithm to find all the alignments between two sequences

Let S and T be two sequences of length n and m, respectively. By calculating the dynamic programming table to find the optimal global alignments between the two sequences S and T, we can hold pointers to find the optimal alignments by following these pointers from cell (n, m) to cell (0,0). Each of the pathways represents a different optimal alignment for the two sequences.

To illustrate, we have an example of a table between the ACGTTA and AACTA sequences. Following the arrows in cell (6,5) to (0,0) we obtain a possible optimal alignment. There are many ways to get to (0,0). Each of those shapes is a different possible optimal alignment.

enter the image description here

The challenge is to find a dynamic programming algorithm that gives me the number of possible routes from this first table, probably by looking at pointers.

Because dynamic programming involves having a programming table, I'm not sure what it should be like. What would be the appropriate policy that determines which cells to look at to find the result in the next cell?

I notice that every possible alignment is a path from (n, m) to (0,0). This implies that each different route is a divergence from a common route.

enter the image description here

You will notice that the red route and the blue route have some parts in common. This seems to justify a dynamic programming solution because we have certain solutions in common that we can use to find the next solution.

My whole problem with this is how I formalize this thinking into a policy that looks like:
enter the image description here

The left part is the initial conditions. Basically it tells you how to find the solution for the following cells based on the previous cells. This is not specific to this problem, it is just an example of what I am looking for.

programming challenge – LeetCode: Median C # Minheap + MaxHeap sliding window

https://leetcode.com/problems/sliding-window-median/

Please check for performance. and coding style, no need to check maximum and minimum heaps.

median is the mean of the two mean values.

Examples: (2,3,4), the median is 3

(2,3), the median is (2 + 3) / 2 = 2.5

Given a set of numbers, there is a sliding window of size k that is
moving from the left of the matrix to the right. You can only
See the k numbers in the window. Every time the sliding window is moved
right in one position. Your job is to generate the median matrix for each
window in the original matrix.

For example, given nums = (1,3, -1, -3,5,3,6,7) and k = 3.

enter the image description here

So return the median sliding window as (1, -1, -1,3,5,6).

Note: You can assume that k is always valid, that is: k is always smaller than
size of the input array for the non-empty array. Answers within 10 ^ -5 of
The actual value will be accepted as correct.

TESTS

    /// 
    /// https://leetcode.com/problems/sliding-window-median/
    /// 
    (TestClass)
    public class SlidingWindowMedianTest
    {
        (TestMethod)
        public void ExampleTest()
        {
            int() nums = { 1, 3, -1, -3, 5, 3, 6, 7 };
            int k = 3;
            double() expected = { 1, -1, -1, 3, 5, 6 };

            SlidingWindowMedianWith2Heaps heaps = new SlidingWindowMedianWith2Heaps();
            var res = heaps.MedianSlidingWindow(nums, k);
            CollectionAssert.AreEqual(expected, res);
        }

        (TestMethod)
        public void ExampleTestFailed()
        {
            int() nums = { 1, 4, 2, 3 };
            int k = 4;
            double() expected = { 2.5 };

            SlidingWindowMedianWith2Heaps heaps = new SlidingWindowMedianWith2Heaps();
            var res = heaps.MedianSlidingWindow(nums, k);
            CollectionAssert.AreEqual(expected, res);
        }

        (TestMethod)
        public void ExampleTestOverFlow()
        {
            int() nums = { 2147483647, 2147483647 };
            int k = 2;
            double() expected = { 2147483647.0 };

            SlidingWindowMedianWith2Heaps heaps = new SlidingWindowMedianWith2Heaps();
            var res = heaps.MedianSlidingWindow(nums, k);
            CollectionAssert.AreEqual(expected, res);
        }

        (TestMethod)
        public void ExampleFailed2()
        {
            int() nums = { 5, 2, 2, 7, 3, 7, 9, 0, 2, 3 };
            int k = 9;
            double() expected = { 3.0, 3.0 };

            SlidingWindowMedianWith2Heaps heaps = new SlidingWindowMedianWith2Heaps();
            var res = heaps.MedianSlidingWindow(nums, k);
            CollectionAssert.AreEqual(expected, res);
        }
    }

CODE Answering the question

public class SlidingWindowMedianWith2Heaps
    {
        public BinaryMaxHeap MaxHeap;
        public BinaryMinHeap MinHeap;

        public double() MedianSlidingWindow(int() nums, int k)
        {
            MaxHeap = new BinaryMaxHeap(k);
            MinHeap = new BinaryMinHeap(k);
            int n = nums.Length - k + 1;
            if (n <= 0)
            {
                return new double(n);
            }

            var result = new double(n);

            for (int i = 0; i <= nums.Length; i++)
            {
                if (i >= k)
                {
                    result(i - k) = GetMedian();
                    Remove(nums(i - k));
                }

                if (i < nums.Length)
                {
                    Add(nums(i));
                }
            }

            return result;
        }

        private void Add(int num)
        {
            if (num < GetMedian())
            {
                MaxHeap.InsertKey(num);
            }
            else
            {
                MinHeap.InsertKey(num);
            }

            if (MaxHeap.Count > MinHeap.Count)
            {
                MinHeap.InsertKey(MaxHeap.ExtractMax());
            }

            if (MinHeap.Count - MaxHeap.Count > 1)
            {
                MaxHeap.InsertKey(MinHeap.ExtractMin());
            }
        }

        private void Remove(int num)
        {
            if (num < GetMedian())
            {
                MaxHeap.DeleteKey(num);
            }
            else
            {
                MinHeap.DeleteKey(num);
            }

            if (MaxHeap._heapSize > MinHeap._heapSize)
            {
                MinHeap.InsertKey(MaxHeap.ExtractMax());
            }

            if (MaxHeap._heapSize - MinHeap._heapSize > 1)
            {
                MaxHeap.InsertKey(MinHeap.ExtractMin());
            }
        }

        private double GetMedian()
        {
            if (MaxHeap.Count == 0 && MinHeap.Count == 0)
            {
                return 0;
            }

            if (MaxHeap.Count == MinHeap.Count)
            {
                return (MaxHeap.GetMax() + (double) MinHeap.GetMin()) / 2.0;
            }
            else
            {
                return MinHeap.GetMin();
            }
        }
    }

MaxHeap

public class BinaryMaxHeap
    {
        private readonly int() _heapArr;
        private readonly int _capacity;
        public uint _heapSize; //current size of heap

        public BinaryMaxHeap(int capacity)
        {
            _capacity = capacity;
            _heapSize = 0;
            _heapArr = new int(capacity);
        }

        public void InsertKey(int key)
        {
            if (_heapSize == _capacity)
            {
                throw new StackOverflowException("overflow can't insert key");
            }

            //insert the new key at the end
            _heapSize++;
            uint i = _heapSize - 1;
            _heapArr(i) = key;

            // fix the heap as max heap
            // Fix the max heap property if it is violated
            while (i != 0 && _heapArr(Parent(i)) < _heapArr(i)) //bubble is generic specific
            {
                Swap(i, Parent(i));
                i = Parent(i);
            }

        }
        public int ExtractMax()
        {
            if (_heapSize <= 0)
            {
                return 0;
            }
            if (_heapSize == 1)
            {
                _heapSize--;
                return _heapArr(0);
            }

            // Store the minimum value, and remove it from heap
            int root = _heapArr(0);
            _heapArr(0) = _heapArr(_heapSize - 1);
            _heapSize--;
            Heapify(0);
            return root;
        }

        private void Heapify(uint i)
        {
            uint l = Left(i);
            uint r = Right(i);
            uint largest = i;
            if (l < _heapSize &&   _heapArr(i) < _heapArr(l))
            {
                largest = l;
            }
            if (r < _heapSize &&   _heapArr(largest) < _heapArr(r))
            {
                largest = r;
            }
            if (largest != i)
            {
                Swap(i, largest);
                Heapify(largest);
            }
        }

        private void Swap(uint key1, uint key2)
        {
            int temp = _heapArr(key2);
            _heapArr(key2) = _heapArr(key1);
            _heapArr(key1) = temp;
        }
        private uint Parent(uint i)
        {
            return (i - 1) / 2;
        }

        private uint Right(uint i)
        {
            return 2 * i + 2;
        }

        private uint Left(uint i)
        {
            return 2 * i + 1;
        }

        public int GetMax()
        {
            return _heapArr(0);
        }

        public uint Count
        {
            get { return _heapSize; }
        }


        public void DeleteKey(int key)
        {
            uint index = 0;
            for (uint i = 0; i < _heapSize; i++)
            {
                if (_heapArr(i) == key)
                {
                    index = i;
                    break;
                }
            }
            DeleteKeyAtIndex(index);
        }
        /// 
        /// This function deletes key at index index. It first increases value to plus
        /// infinite, then calls extractMax()
        /// 
        private void DeleteKeyAtIndex(uint index)
        {
            IncreaseKey(index, int.MaxValue);
            ExtractMax();
        }

        private void IncreaseKey(uint i, int newValue)
        {
            _heapArr(i) = newValue;
            while (i != 0 && _heapArr(Parent(i)) < _heapArr(i)) //bubble is generic specific
            {
                Swap(i, Parent(i));
                i = Parent(i);
            }
        }
    }

MinHeap

public class BinaryMinHeap
    {
        private readonly int() _heapArr;// pointer to array of elements in heap
        private readonly int _capacity; // maximum possible size of min heap
        public uint _heapSize; // Current number of elements in min heap

        public BinaryMinHeap(int capacity)
        {
            _capacity = capacity;
            _heapSize = 0;
            _heapArr = new int(capacity);
        }

        public void InsertKey(int key)
        {
            if (_heapSize == _capacity)
            {
                throw new StackOverflowException("overflow can't insert key");
            }

            //insert the new key at the end
            _heapSize++;
            uint i = _heapSize - 1;
            _heapArr(i) = key;

            //fix the heap  as min heap
            // Fix the min heap property if it is violated
            while (i != 0 && _heapArr(Parent(i)) > _heapArr(i)) //bubble is generic specific
            {
                Swap(i, Parent(i));
                i = Parent(i);
            }
        }


        public void DeleteKey(int key)
        {
            uint index = 0;
            for (uint i = 0; i < _heapSize; i++)
            {
                if (_heapArr(i) == key)
                {
                    index = i;
                    break;
                }
            }
            DeleteKeyAtIndex(index);
        }
        /// 
        /// This function deletes key at index index. It first reduced value to minus
        /// infinite, then calls extractMin()
        /// 
        public void DeleteKeyAtIndex(uint index)
        {
            DecreaseKey(index, int.MinValue);
            ExtractMin();
        }

        public void DecreaseKey(uint i, int newValue)
        {
            _heapArr(i) = newValue;
            while (i != 0 && _heapArr(Parent(i)) > _heapArr(i)) //bubble is generic specific
            {
                Swap(i, Parent(i));
                i = Parent(i);
            }
        }
        /// 
        /// you switch the root with the last index in the array, the end of the heap
        /// and you heapify the root node.
        /// 
        /// 
        public int ExtractMin()
        {
            if (_heapSize <= 0)
            {
                return int.MaxValue;
            }
            if (_heapSize == 1)
            {
                _heapSize--;
                return _heapArr(0);
            }

            // Store the minimum value, and remove it from heap
            int root = _heapArr(0);
            _heapArr(0) = _heapArr(_heapSize - 1);
            _heapSize--;
            Heapify(0);
            return root;
        }
        /// 
        /// the first call is done with index 0,
        /// since this is recursive function you compare to right subtree and left subtree
        /// you choose the lower node and swap the root with it, than you call
        /// the same function from the last index you swapped with
        /// 
        /// 
        private void Heapify(uint i)
        {
            uint l = Left(i);
            uint r = Right(i);
            uint smallest = i;
            if (l < _heapSize && _heapArr(l) < _heapArr(i))
            {
                smallest = l;
            }
            if (r < _heapSize && _heapArr(r) < _heapArr(smallest))
            {
                smallest = r;
            }
            if (smallest != i)
            {
                Swap(i, smallest);
                Heapify(smallest);
            }
        }

        private uint Right(uint i)
        {
            return 2 * i + 2;
        }

        private uint Left(uint i)
        {
            return 2 * i + 1;
        }

        private uint Parent(uint i)
        {
            return (i - 1) / 2;
        }

        private void Swap(uint key1, uint key2)
        {
            int temp = _heapArr(key2);
            _heapArr(key2) = _heapArr(key1);
            _heapArr(key1) = temp;
        }

        public int GetMin()
        {
            return _heapArr(0);
        }
        public uint Count
        {
            get { return _heapSize; }
        }
    }

postgresql – Difference between Postgres Unix Time and programming languages

I wonder why PostgreSQL returns Time Unix as double precision instead of going back bigint or in long or int64 like programming languages?
I need to compare a Unix Time generated by programming languages, with the Unix Time generated by PostgreSQL through extrach(epoch), but the values ​​are totally different.

1584902629086    -- Gerado em Java/JavaScript/GoLang/PHP
1584715252.10093 -- Gerado no PostgreSQL

How can I convert any of the values ​​to be able to work?

What programming language should I learn to teach mathematics and physics through animation?

Stack Exchange Network

The Stack Exchange network consists of 175 question and answer communities, including Stack Overflow, the largest and most trusted online community for developers to learn, share their insights, and develop their careers.

Visit Stack Exchange

programming challenge – LeetCode: Median C # Sliding Window

https://leetcode.com/problems/sliding-window-median/

The median is the mean value in an ordered integer list. If the size of
the list is even, there is no mean value. So the median is the mean
of the two mean values.

Examples: (2,3,4), the median is 3

(2,3), the median is (2 + 3) / 2 = 2.5

Given a set of numbers, there is a sliding window of size k that is
moving from the left of the matrix to the right. You can only
See the k numbers in the window. Every time the sliding window is moved
right in one position. Your job is to generate the median matrix for each
window in the original matrix.

For example, given nums = (1,3, -1, -3,5,3,6,7) and k = 3.

enter the image description here

So return the median sliding window as (1, -1, -1,3,5,6).

Note: You can assume that k is always valid, that is: k is always smaller than
size of the input array for the non-empty array. Answers within 10 ^ -5 of
The actual value will be accepted as correct.

Please check for performance. Also, I'm not sure about the GetID function. Is there a smarter way to get the same result from a unique number and median ranking?

using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace TreeQuestions
{
    /// 
    /// https://leetcode.com/problems/sliding-window-median/
    /// 
    (TestClass)
    public class SlidingWindowMedianTest
    {
        (TestMethod)
        public void ExampleTest()
        {
            int() nums = { 1, 3, -1, -3, 5, 3, 6, 7 };
            int k = 3;
            double() expected = { 1, -1, -1, 3, 5, 6 };
            double() res = SlidingWindowMedian.MedianSlidingWindow(nums, k);
            CollectionAssert.AreEqual(expected, res);
        }

        (TestMethod)
        public void ExampleTestFailed()
        {
            int() nums = { 1, 4, 2, 3 };
            int k = 4;
            double() expected = { 2.5 };
            double() res = SlidingWindowMedian.MedianSlidingWindow(nums, k);
            CollectionAssert.AreEqual(expected, res);
        }

        (TestMethod)
        public void ExampleTestOverFlow()
        {
            int() nums = { 2147483647, 2147483647 };
            int k = 2;
            double() expected = { 2147483647.0 };
            double() res = SlidingWindowMedian.MedianSlidingWindow(nums, k);
            CollectionAssert.AreEqual(expected, res);
        }

        (TestMethod)
        public void ExampleFailed2()
        {
            int() nums = { 5, 2, 2, 7, 3, 7, 9, 0, 2, 3 };
            int k = 9;
            double() expected = { 3.0, 3.0 };
            double() res = SlidingWindowMedian.MedianSlidingWindow(nums, k);
            CollectionAssert.AreEqual(expected, res);
        }
    }



    public class SlidingWindowMedian
    {
        public static double() MedianSlidingWindow(int() nums, int k)
        {
            var res = new List();
            var med = new SortedList();
            for (int i = 0; i < nums.Length; i++)
            {
                med.Add(GetId(i, nums), nums(i));
                if (med.Count > k)
                {
                    med.Remove(GetId(i - k, nums));
                }

                if (med.Count == k)
                {
                    if (k % 2 == 0)
                    {
                        res.Add( ((long)med(med.Keys(k / 2 - 1))  + med(med.Keys(k / 2)))/2.0 );
                    }
                    else
                    {
                        res.Add(med(med.Keys(k / 2)));
                    }
                }
            }
            return res.ToArray();

        }

        private static long GetId(int i, int() nums)
        {
            return Convert.ToInt64(nums(i)) * nums.Length + i;
        }
    }

}

software engineering: avoiding global variables in event-driven programming

First of all, is "procedural event driven programming" one thing? My question is about global variables in the context of an event-driven program that doesn't use OOP …

I have written a simple Snake game in Python that makes modest use of global variables. I have been warned about global ills so often that I thought I would try to refactor the program to pass arguments.

It seems to me that any aspect of elegance or simplicity was lost in this effort. The version with globals is shown at the end of this publication. Here is an excerpt from my refactoring attempt:

def go_up(screen, pen, snake, snake_direction, food):
    if snake_direction != "down":
        snake_direction = "up"
        move_snake(screen, pen, snake, snake_direction, food)



    # Event handlers
    screen.listen()
    screen.onkey(lambda: go_up(screen, pen, snake, snake_direction, food), "Up")
    screen.onkey(lambda: go_right(screen, pen, snake, snake_direction, food), "Right")
    screen.onkey(lambda: go_down(screen, pen, snake, snake_direction, food), "Down")
    screen.onkey(lambda: go_left(screen, pen, snake, snake_direction, food), "Left")

    # Let's go
    snake = ()
    snake_direction = ""
    screen, pen, snake, snake_direction, food = reset(screen, pen, snake, snake_direction, food)
    turtle.done()

It got very messy very fast and I couldn't recreate the same functionality.

I'm pretty sure that even with a simple game like this, using OOP would be preferable to a procedural approach that involves passing as many arguments.

But assuming I don't want to use OOP, let's say I want to teach kids how to write fun games without digging in, is there any merit in using the pass the argument approach over what seems to me the much simpler approach? of having some global variables?

Is this code evil?

"""
A simple snake game using Turtle Graphics.
Todo:  border collision?, score
"""
import turtle
import random

WIDTH = 500
HEIGHT = 500
FOOD_SIZE = 10
DELAY = 100  # milliseconds

offsets = {
    "up": (0, 20),
    "down": (0, -20),
    "left": (-20, 0),
    "right": (20, 0)
}


def reset():
    global snake, snake_direction
    snake = ((0, 0), (0, 20), (0, 40), (0, 50), (0, 60))
    snake_direction = "up"
    food_pos = get_random_food_pos()
    food.goto(food_pos)
    # screen.update() Only needed if we are fussed about drawing food before call to `draw_snake()`.
    move_snake()


def move_snake():

    #  Next position for head of snake.
    new_head = snake(-1).copy()
    new_head(0) = snake(-1)(0) + offsets(snake_direction)(0)
    new_head(1) = snake(-1)(1) + offsets(snake_direction)(1)

    # Check self-collision
    if new_head in snake(:-1):  # Or collision with walls?
        reset()
    else:
        # No self-collision so we can continue moving the snake.
        snake.append(new_head)

        # Check food collision
        if not food_collision():
            snake.pop(0)  # Keep the snake the same length unless fed.

        #  Allow screen wrapping
        if snake(-1)(0) > WIDTH / 2:
            snake(-1)(0) -= WIDTH
        elif snake(-1)(0) < - WIDTH / 2:
            snake(-1)(0) += WIDTH
        elif snake(-1)(1) > HEIGHT / 2:
            snake(-1)(1) -= HEIGHT
        elif snake(-1)(1) < -HEIGHT / 2:
            snake(-1)(1) += HEIGHT

        # Clear previous snake stamps
        pen.clearstamps()

        # Draw snake
        for segment in snake:
            pen.goto(segment(0), segment(1))
            pen.stamp()

        # Refresh screen
        screen.update()

        # Rinse and repeat
        turtle.ontimer(move_snake, DELAY)


def food_collision():
    if get_distance(snake(-1), (food.xcor(), food.ycor())) < 20:
        food_pos = get_random_food_pos()
        food.goto(food_pos)
        return True
    return False


def get_random_food_pos():
    x = random.randint(- WIDTH / 2 + FOOD_SIZE, WIDTH / 2 - FOOD_SIZE)
    y = random.randint(- HEIGHT / 2 + FOOD_SIZE, HEIGHT / 2 - FOOD_SIZE)
    return (x, y)


def get_distance(pos1, pos2):
    x1, y1 = pos1
    x2, y2 = pos2
    distance = ((y2 - y1) ** 2 + (x2 - x1) ** 2) ** 0.5
    return distance


def go_up():
    global snake_direction
    if snake_direction != "down":
        snake_direction = "up"


def go_right():
    global snake_direction
    if snake_direction != "left":
        snake_direction = "right"


def go_down():
    global snake_direction
    if snake_direction != "up":
        snake_direction = "down"


def go_left():
    global snake_direction
    if snake_direction != "right":
        snake_direction = "left"


def main():
    global screen, pen, food

    # Screen
    screen = turtle.Screen()
    screen.setup(WIDTH, HEIGHT)
    screen.title("Snake")
    screen.bgcolor("green")
    screen.setup(500, 500)
    screen.tracer(0)

    # Pen
    pen = turtle.Turtle("square")
    pen.penup()

    # Food
    food = turtle.Turtle()
    food.shape("circle")
    food.color("red")
    food.shapesize(FOOD_SIZE / 20)  # Default size of turtle "square" shape is 20.
    food.penup()

    # Event handlers
    screen.listen()
    screen.onkey(go_up, "Up")
    screen.onkey(go_right, "Right")
    screen.onkey(go_down, "Down")
    screen.onkey(go_left, "Left")

    # Let's go
    reset()
    turtle.done()


if __name__ == "__main__":
    main()

Java – Missing scenarios in the minimal platform programming exercise

I am trying to solve the minimum platform in geeks for geeks. When submitting the code, one of the test cases is failing, but after a good amount of time has passed, I can't understand what I'm doing wrong.

Please refer to the code below and help me determine which scenario is missing.

Here is a description of what I am trying to do:

  1. Order both matrices
  2. I am an indicator of the next train that will leave any station to make room for the incoming train. Initially established on the first train
  3. For each remaining train, if the train's arrival time is greater than I's departure time, increase the count or move I until the departure time is less than the train's next arrival time.

Here is the code:

int count(int() arrival, int() departure) {
    if (arrival.length != departure.length) {
        throw new RuntimeException("Wrong data");
    }

    Arrays.sort(arrival);
    Arrays.sort(departure);

    int platformCount = 1;
    if (arrival.length <= 1) {
        return platformCount;
    }
    int i = 0; //pointer to train, which will be first to depart
    for (int j = 1; j < arrival.length-1; j++) {
        if (arrival(j) <= departure(i)) {
            platformCount++;
        } else {
            while (i < j && arrival(j+1) > departure(i)) {
                i++;
            }
        }
    }
    return platformCount;
}