human
Number of ways such that only K bars are visible from the left | Function to calculate the number of bars that are visible from the left for a particular arrangement.
If current element is greater than the last greater element , it is visible.
Function to calculate the number of rearrangements where K bars are visiblef from the left.
Vector to store current permutation.
Check for all permutations.
If current permutation meets the conditions , increment answer.
Driver code.
Input.
Function call"
Solution in Python:
 Write me a code to number of ways such that only K bars are visible from the left and the other steps required?
assistant
#Here is code to number of ways such that only K bars are visible from the left and the other steps required.
 def noOfbarsVisibleFromLeft ( v ) :
	last = 0
	ans = 0
	for u in v :
		if ( last < u ) :
			ans += 1
			last = u
	return ans
def nextPermutation ( nums ) :
	i = len ( nums ) - 2
	while i > - 1 :
		if nums [ i ] < nums [ i + 1 ] :
			j = len ( nums ) - 1
			while j > i :
				if nums [ j ] > nums [ i ] :
					break
				j -= 1
			nums [ i ] , nums [ j ] = nums [ j ] , nums [ i ]
			break
		i -= 1
	nums [ i + 1 : ] = reversed ( nums [ i + 1 : ] )
	return nums
def KvisibleFromLeft ( N , K ) :
	v = [ 0 ] * ( N )
	for i in range ( N ) :
		v [ i ] = i + 1
	ans = 0
	temp = list ( v )
	while True :
		if ( noOfbarsVisibleFromLeft ( v ) == K ) :
			ans += 1
		v = nextPermutation ( v )
		if v == temp :
			break
	return ans
if __name__ == ' _ _ main _ _ ' :
	N = 5
	K = 2
	print ( KvisibleFromLeft ( N , K ) )