bad code to get file-type:-

best practice to get file-type:-

python-magic is a Python interface to the libmagic file type identification library. libmagic identifies file types by checking their headers according to a predefined list of file types. This functionality is exposed to the command line by the Unix command file.

This class uses pymysql package to do the database interaction.

A frog jumps either 1, 2 or 3 steps to go to top. In how many ways can it reach the top.

Let’s Define Dp solution using recursive

Given an M X N matrix with your initial position at the top-left cell, find the number of possible unique paths to reach the bottom-right cell of the matrix from the initial position.

Note: Possible moves can be either down or right at any point in time, i.e., we can move to matrix[i+1][j] or matrix[i][j+1] from matrix[i][j].

Recursive Solution for Above Question

Using Recursive Solution let’s find Dp solution for that,

Given a number n, we can divide it into only three parts n/2, n/3, and n/4 (we will consider only integer part). The task is to find the maximum sum we can make by dividing the number into three parts recursively and summing up them together.
Note: Sometimes, the maximum sum can be obtained by not dividing n.

start with the minimum solution n=0 then max sum=0 now n=1 , maxsum=1 so on. so we find a recursive solution like max(n//2+n//3+n//4,n).

Number of subsequences of the form a^i b^j c^k

Given a string, count number of subsequences of the form a^ib^jc^k, i.e., it consists of i ’a’ characters, followed by j ’b’ characters, followed by k ’c’ characters where i >= 1, j >=1 and k >= 1.

sohesh doshi

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store