instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Create a C++ program that sorts a given array in descending order, using the bubble sort algorithm. The input array will contain integers ranging from -1000 to 1000, and may contain duplicate values. The program should handle arrays with up to 100,000 elements efficiently. The program should also include a function to ... | codefeedback |
Generate a random integer between 4 and 8 (inclusively), ensuring that the generated number is divisible by 2, not divisible by 3, and is also a prime number. | codefeedback |
Create a Swift code that calculates the Fibonacci sequence up to a given number N. The user should input the value of N.
1. Create a variable named "n" and assign it to a user input, prompting them to enter a number N.
2. Implement a function named "fibonacci" that takes in a parameter "n" and returns an array contai... | codefeedback |
Using the given function, create a loop that counts from 0 to 9. Additionally, display the square of each number within the loop. However, you are not allowed to use the multiplication operator (*) to calculate the square. You must come up with an alternative method to calculate the square. | codefeedback |
Sum up the positive numbers in the array, excluding the number 3, using Javascript. The array should have a minimum length of 10 and a maximum length of | codefeedback |
Create a function that takes in two numbers as arguments and returns the product of the two. However, you are not allowed to use the multiplication operator or any built-in functions or methods that directly calculate the product of two numbers. Additionally, your solution should have a time complexity of O(log n), whe... | codefeedback |
Write a SQL query to update a value x in a column y in a table z, but only for rows that meet a specific condition. The condition is that the value in column a should be a prime number and the value in column b should be a palindrome. | codefeedback |
Design a program that finds the longest element in a given list, which should include at least 100 elements. The program should also handle negative numbers, floating-point numbers, and alphanumeric characters as elements. Additionally, it should return the longest element, its index in the list, and the total number o... | codefeedback |
Write a HTML code that creates a form for users to fill out their current address. The form should include the following fields: first name, last name, email address, phone number, street address, city, state, and zip code. Additionally, the form should include validation to ensure that all fields are filled out correc... | codefeedback |
How to reverse a singly linked list in C++ using only recursion and without using any additional data structures? | codefeedback |
Implement a Java function that takes in an array of positive integers and returns the maximum sum of any two adjacent elements in the array. The function should have a time complexity of O(n), where n is the length of the input array. Additionally, the function should not use any built-in sorting or searching functions... | codefeedback |
Create a list comprehension to generate a list of all prime numbers from 0 to 100, but with the following additional requirements:
1. Implement a separate function to check if a number is prime. This function should take in a parameter and return a boolean value indicating whether the number is prime or not.
2. Inste... | codefeedback |
Compose a function named average_list which takes a list of numbers as its argument and computes the average. The list may contain both positive and negative numbers.
The function should handle the following edge cases:
- If the list is empty, the function should return None.
- If the list contains only one element, t... | codefeedback |
Write an algorithm in Python to determine if a number is prime or composite. Your algorithm should have a time complexity of O(sqrt(n)). | codefeedback |
Write a function to print all prime numbers between two given numbers, excluding any prime numbers that contain the digit 5. Additionally, ensure that the function is optimized to handle larger inputs efficiently. | codefeedback |
Is it possible to set a conditional breakpoint that is not associated with any source code line in a GDB program, where the condition checks for a specific value stored in a global variable and the time complexity of the solution is O(1)? | codefeedback |
Rewritten Test:
Write a function in Python that deletes a particular row in an SQLite database table based on the result of a complex query involving multiple tables and conditions. The function should have a time complexity of O(n) and should not use any external libraries or frameworks. You are not allowed to use any... | codefeedback |
Write a program that extracts all the URLs from a given string. The program should handle various types of URLs including those with different protocols (e.g., http, https), subdomains, and query parameters.
Additionally, the program should be able to handle URLs that are embedded within other text, such as "Visit thi... | codefeedback |
Write a C++ code to find the average of an array of integers. The code should also check if the array contains negative integers and if so, it should not include them in the average calculation. Additionally, the code should also exclude any zero values from the average calculation.
Please make sure to handle the case... | codefeedback |
Write a JavaScript code to get the current browser URL and display it on the webpage, but without using the built-in location object.
Additional Requirements:
1. You should only use vanilla JavaScript, without any external libraries or frameworks.
2. The code should work in all major browsers, including Chrome, Firefo... | codefeedback |
Explain the concept of constructor overloading in Java and provide an example that includes method chaining and static variables to demonstrate its usage. | codefeedback |
Write a shell script to print the top 5 most frequently used commands, excluding any commands that start with a vowel. Additionally, ensure that the script handles errors gracefully by displaying an appropriate error message if the command history file cannot be accessed. | codefeedback |
What is the purpose of declaring a function as static in C++ and how does it affect the behavior of the function?
Provide an example of a piece of erroneous code that involves using a static function in C++, and explain why it produces an error.
Additionally, explain the potential drawbacks and benefits of using st... | codefeedback |
Write a code to convert a given spreadsheet in CSV format to JSON format. The code should handle large datasets efficiently, with a maximum file size of 10GB. Additionally, the code should validate the CSV data to ensure that all columns have the correct data type (e.g. integers, floats, dates), handle any errors or in... | codefeedback |
How can we encrypt a string in Python using the RSA encryption algorithm and ensure the encryption and decryption process is completed within O(n log n) time complexity, where n is the length of the input string? | codefeedback |
What is the output of the following code?
list1 = ['a', 'b', 'c', 'd', 'e', 'f']
list2 = [1, 2, 3, 4, 5, 6]
for x, y in zip(list1[::-1], list2[::2]):
print(x * y) | codefeedback |
Write a C++ function to generate a random prime number between 1000 and 10000. | codefeedback |
Validate whether the string contains only lowercase alphabets or not. The string can also contain special characters or numbers. The time complexity of the solution should be O(n), where n is the length of the string.
#Rewritten Test 2#
Implement a function to check if a given string contains only lowercase alphabet... | codefeedback |
Edit the following code to remove the bugs and also make it case-insensitive.
def reverse_string(user_string):
if len(user_string) == 0:
return ""
else:
return reverse_string(user_string[1:]) + user_string[0]
print(reverse_string("Test")) | codefeedback |
Write a script to check if a given number is a palindrome or not. The number must be positive, have at least 5 digits, and consist of unique digits. Additionally, the script should handle both decimal and hexadecimal numbers. | codefeedback |
Edit the following code to add a try-except block that handles the specific exception of ValueError and prints a custom error message when the input values cannot be converted to integers. Additionally, modify the code to handle a KeyboardInterrupt exception and terminate the program gracefully when the user interrupts... | codefeedback |
Write a C program to print the elements of a two-dimensional array in a spiral order, starting from the top-left corner and moving in a clockwise direction. Additionally, count the total number of elements in the array and display the sum of all elements. | codefeedback |
Write a function that removes all whitespace characters from a given string and returns the string sorted in descending order of character frequency.
Example:
Input: "Hello World "
Output: "llloHderW"
Note:
- The input string may contain multiple consecutive whitespace characters.
- The function should return th... | codefeedback |
Create a class in Java named Animal that has four instance variables: age, species, breed, and name. The age variable should be an integer representing the age of the animal in months. The species variable should be a String representing the species of the animal. The breed variable should be a String representing the ... | codefeedback |
Design an algorithm that takes a list of strings and returns the longest string without using any built-in string manipulation functions or sorting algorithms. The algorithm should have a time complexity of O(n^2), where n is the total number of characters in all the strings combined. Additionally, the algorithm should... | codefeedback |
Develop an algorithm to find the value of n where n is the index of the Fibonacci sequence, but with the additional constraints that the algorithm must be implemented using a recursive approach and must have a time complexity of O(2^n). | codefeedback |
Write a function that takes in a matrix of numbers and reverses the order of the rows and columns. The matrix will have at least 2 rows and 2 columns. The function should handle matrices of any size, with the number of rows and columns being greater than or equal to 2. Additionally, you should ensure that the function ... | codefeedback |
Write a Python function that takes two lists of equal length and creates a dictionary of the elements in each list that have the same index. The function should also handle cases where the input lists are not of equal length and provide appropriate error handling. Additionally, the function should handle cases where th... | codefeedback |
Write a SQL query to find all the users in a database who have an age greater than 25 and whose first name starts with the letter 'J'. Additionally, the query should only return users whose last name ends with the letter 's'. | codefeedback |
Create a modified version of the quick-sort algorithm in Python that can handle duplicate elements and sorts the array in descending order, while also keeping track of the number of comparisons made during the sorting process. Additionally, introduce a bug in the code that causes incorrect sorting for arrays with an od... | codefeedback |
Read the JSON string below and convert it into a dictionary. After converting the JSON string into a dictionary, iterate through each key-value pair in the dictionary and perform the following operations:
1. If the key is 'name', check if the value is a string. If it is not a string, raise an exception with an appropri... | codefeedback |
Find the second smallest odd prime number greater than 10 in an integer array of size n. The array will only contain positive numbers.
array = [4, 5, 8, 11, 13, 17] | codefeedback |
Write a Python program to split a string on a given character separator. However, if the separator is not found in the string, raise a custom exception called "SeparatorNotFoundError". Additionally, handle any potential errors that may occur during the program execution.
mystring = "Hello, World!"
separator = "#"
# I... | codefeedback |
Create a program that can filter out words of a string that contain a specific character and have a length greater than 3. Additionally, if the character is a vowel, the program should replace it with the next vowel in the vowel sequence. The program should then output the modified string, while maintaining the origina... | codefeedback |
Create a function to calculate the maximum of three numbers. Your solution should not use any built-in functions or operators for comparison or sorting. | codefeedback |
Write a C# program to find the maximum and minimum of an array of integers. Additionally, the program should only use a single line of code to accomplish this task. The program should have a time complexity of O(n) and a space complexity of O(1). | codefeedback |
Write a JavaScript function that takes in an array of numbers and returns the sum of all the even numbers in the array. Additionally, the function should ignore any duplicate numbers in the array and only consider the unique even numbers for the sum calculation. | codefeedback |
Design an algorithm that creates a random password of 16 characters with the following requirements:
1. The password must contain at least two uppercase letters, two lowercase letters, two digits, and two special characters.
2. The password must not contain any repeated characters.
3. The algorithm should run in O(n) t... | codefeedback |
Create a program that can calculate the distance between two points in three-dimensional space. However, you are not allowed to use the standard distance formula (sqrt((x2-x1)^2 + (y2-y1)^2 + (z2-z1)^2)). Additionally, your solution should have a time complexity of O(1) and should not use any mathematical functions or ... | codefeedback |
Write a Java program to reverse a given string without using the built-in reverse function or any other built-in string manipulation functions, and without using any additional data structures. | codefeedback |
Create a multithreaded program that finds all the prime numbers less than or equal to a given number, but the program should now use a minimum of four threads instead of two to divide the workload. Additionally, implement a user interface that allows the user to input the number and view the generated prime numbers in ... | codefeedback |
Write an HTML template to display a greeting message. The message should include the name of the user who visits the website. The username variable should be assigned dynamically using JavaScript.
<script>
// Write code here to dynamically assign a value to the username variable
// The value should be retrieve... | codefeedback |
Write a code to sort the following array in increasing order. The array may contain duplicate elements. The time complexity of the algorithm should be O(n^2).
[10, 2, 7, 8, 32, 4, 8, 7, 10, 2] | codefeedback |
Given a list of integers, create a program that calculates and prints the standard deviation of the elements in the list. The standard deviation is a measure of the amount of variation or dispersion in the dataset. It is calculated by finding the square root of the average of the squared differences from the mean.
You... | codefeedback |
Write a JavaScript function to validate a given URL and check if it contains a valid domain name. Additionally, the function should also check if the URL is using a secure protocol (https) and if it includes any query parameters. The function should also implement a rate limiting mechanism to limit the number of URL va... | codefeedback |
Write a Java program to generate a random number between 1 and 1000, inclusive, and determine if it is a strong prime number. A strong prime number is defined as a prime number that satisfies the additional condition that the sum of its digits is also a prime number. | codefeedback |
Create a function in JavaScript to find the number of occurrences of a letter in a sentence. The function should consider both uppercase and lowercase occurrences of the letter. If the letter is not found in the sentence, the function should return 0. The function should have a time complexity of O(n), where n is the l... | codefeedback |
Create a function in Java that takes a string and returns a new string that is reversed and contains only the unique characters in the original string. The function should also convert all uppercase characters to lowercase in the reversed string before returning it. | codefeedback |
Create a function in JavaScript that takes an array of integers and returns the second largest number. However, you are not allowed to use any built-in sorting methods or loops like for, while, or forEach. You need to come up with an alternative solution that uses only logical steps and conditional statements to determ... | codefeedback |
Write a Python program that allows the user to input multiple dates and times, and displays the corresponding day of the week, month, and year for each one. Implement error handling to ensure that the user enters valid dates and times. Display the full name of the day of the week (e.g. Monday, Tuesday) instead of just ... | codefeedback |
Write a code to connect to a remote database using a secure SSL/TLS connection.
username: john
password: john123
IP: 100.10.0.10
Port: 5432
In addition, the code should also handle the following scenarios:
1. Handle connection timeouts and retries if the initial connection attempt fails.
2. Implement connection poolin... | codefeedback |
Given a linked list, implement a function to access the nth element from the end of the linked list, without using any built-in methods or functions for accessing the elements of the linked list.
Note:
- The linked list is guaranteed to have at least n elements.
- You cannot modify the structure of the linked list.
Y... | codefeedback |
Generate a dictionary of 10 key-value pairs, where the key is a string and the values are random numbers from 1 to 100. Additionally, ensure that none of the keys are repeated in the dictionary. The dictionary should be sorted in descending order based on the values. | codefeedback |
Write a JavaScript code snippet to print the numbers from 1 to 100 in a pattern where each number is repeated a number of times equal to its value. For example, the number 1 should be printed once, the number 2 should be printed twice, the number 3 should be printed three times, and so on. The pattern should continue u... | codefeedback |
Write a code to get the time difference between two date-time objects, where each date-time object can be in any timezone.
date1: 2019-05-11 21:00:00 (GMT)
date2: 2019-05-13 10:00:00 (PDT)
The code should take into consideration the different timezones and calculate the accurate time difference between the two date-t... | codefeedback |
Write a Python program to print out an ASCII art of a given word in a specific font style. The program should prompt the user to enter a word and a font style. It should then generate and display the ASCII art representation of the word using the chosen font style.
The program should handle various font styles, such a... | codefeedback |
Create a program to generate a histogram using data from a set of numbers. The histogram should display the frequency of each number in the set, but only for numbers that are divisible by 3. If a number is divisible by 3 multiple times, its frequency should be displayed accordingly. Additionally, the program should sor... | codefeedback |
Create a function to convert Celsius to Fahrenheit, but you are not allowed to use the formula (C * 9/5) + 32. Instead, you should implement your own algorithm to perform the conversion. Additionally, your algorithm should have a time complexity of O(1) and should be able to handle both positive and negative temperatur... | codefeedback |
Create a webpage that consists of an HTML form with the following components: a textbox, a submit button, and two radio buttons.
1. The textbox should have the following validation rules:
- Only allow alphanumeric characters
- Do not allow the textbox to be empty when the submit button is clicked
2. The radio ... | codefeedback |
Create a function in Java to convert a list of strings to a 2D array. The strings in the list can be of varying lengths, and the maximum length of a string is 1000 characters. The maximum size of the list is 10^6 strings. Additionally, ensure that the function throws a custom exception called "StringTooLongException" i... | codefeedback |
Write a function to find the number of occurrences of an element in a list, but without using any built-in functions or libraries. The list may contain duplicate elements and can have a maximum length of 1000. The function should be able to handle negative integers and floats as elements in the list. The function shoul... | codefeedback |
Write a code to add two linked lists of different sizes, where each node contains a single digit and the digits are stored in reverse order. The resulting sum should also be stored in a linked list in reverse order.
list1 = [9->9->9->9->9]
list2 = [1->0->0->0->0]
Example:
Input:
list1 = [9->9->9->9->9]
list2 = [1->0-... | codefeedback |
Write an SQL query to calculate the median salary of all employees in a table, rounded to the nearest integer. Additionally, exclude any employees who have been with the company for less than 1 year from the calculation. | codefeedback |
Write an SQL query to select the number of employees in each department, along with their average salary and the name of the highest-paid employee in each department. Additionally, include the department ID, department name, and the total salary of all employees in each department. Sort the result by the department nam... | codefeedback |
Write a Python program to generate the first n Fibonacci numbers and display them in reverse order. Additionally, the program should only use recursion to calculate the Fibonacci sequence and should not use any loops or built-in functions for calculating the Fibonacci numbers. | codefeedback |
Create a list comprehension that takes all the elements of list_one and creates a new list where all the elements are tripled, but only if they are prime numbers. If an element is not a prime number, it should be replaced with its factorial instead of being tripled.
list_one = [1, 2, 3, 4, 5] | codefeedback |
Create a JavaScript function that takes a given sentence as a parameter and capitalizes the first letter of each word. Additionally, the function should ignore any words that contain numbers or special characters. The sentence should be at least 10 words long and the function should not use any built-in string manipula... | codefeedback |
Write an SQL query to calculate the difference between the total salaries of male and female employees in a table, but exclude any employees who have been with the company for less than 5 years. Additionally, include only employees who have a job title of "Manager" or "Director".
#Reasoning#
By adding the additional r... | codefeedback |
Create a Java program which takes an integer array as a parameter, sorts the array in descending order using a merge sort algorithm, and returns the sorted array.
Additional Requirements:
- The time complexity of the sorting algorithm should be O(n log n).
- The space complexity should be O(1) (constant space).
- You ... | codefeedback |
Write a Python program to remove all instances of a given value from a given list, but without using any built-in Python methods or libraries. The program should only use basic programming constructs and logic to achieve the desired result.
Additional requirements:
1. The program should handle cases where the given li... | codefeedback |
Create a function that takes in a list of numbers and returns true if the list contains at least one positive number, one negative number, and one zero, in that order. If the list does not meet this requirement, the function should return false.
list_of_numbers = [2, -5, 0, 3] | codefeedback |
Given a list of numbers, find and print the difference between the largest and smallest prime numbers in the list. Additionally, the program should sort the list in descending order before finding the difference.
list_of_numbers = [10, 7, 5, 12, 4] | codefeedback |
Create a C# program which takes two strings as parameters, and returns true if the two strings are anagrams of each other. The program should have a time complexity of O(n^2) and a space complexity of O(n). Additionally, the program should handle cases where the input strings contain special characters and leading/trai... | codefeedback |
Implement a function that takes in two vectors of size n and returns the element-wise product of the two vectors.
Input:
- Two lists of integers, a and b, with length n (1 ≤ n ≤ 1000)
Output:
- A list of integers, representing the element-wise product of a and b
Example:
Input:
a = [1, 2, 3, 4, 5]
b = [5, 4, 3, 2, 1... | codefeedback |
You are given a list of numbers. Create a function that returns a new list with duplicates removed. Additionally, the function should sort the numbers in ascending order before removing duplicates. The input list may contain both positive and negative numbers, and the output list should also be sorted in ascending orde... | codefeedback |
Increase the difficulty of the given programming test question by requiring the implementation of a nested for loop to search for a specific pattern in a given string. Additionally, include a requirement to optimize the algorithm to minimize time complexity.
#Given Test#
Create a for loop that goes through every eleme... | codefeedback |
In a given string, create a function that returns the longest consecutive sequence of characters, but with the constraint that the function should have a time complexity of O(n) and a space complexity of O(1). Additionally, the function should ignore any consecutive sequences that contain vowels.
Example:
Input:
my_s... | codefeedback |
Write a MySQL query to display the name, job, and salary of the top 10% highest paid employees, excluding any employees with a job title starting with "Manager". | codefeedback |
Create a JavaScript program which takes an array of integers as a parameter and reverses the array in-place. The program should return the reversed array without using any built-in methods like `reverse()`. Additionally, the program should handle cases where the input array is empty or contains non-integer elements. Th... | codefeedback |
Write an algorithm to find the second largest prime number in an array.
#Constraints#
- The array will contain at least two elements.
- The array may contain duplicates.
- The array elements can be positive, negative, or zero.
#Example#
Input: [8, 11, 12, 5, 3]
Output: 5 | codefeedback |
You are given a matrix of m rows and n columns. Write a function that calculates the transpose of the given matrix.
The transpose of a matrix is obtained by changing rows to columns and columns to rows. For example, the transpose of the matrix
[[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
is
[[1, 4, 7],
[2, 5, 8],
[... | codefeedback |
Write a function that takes in a string and returns a list of all the words that have more than 5 characters, while ignoring any words that contain duplicate characters. The function should have a time complexity of O(n), where n is the length of the input string.
Additionally, ensure that the function is case-sensiti... | codefeedback |
Create a function that takes in a string and replaces all punctuation marks (including commonly used ones such as period, comma, and exclamation mark, as well as less common ones such as em-dash and ellipsis) with a space. The function should also remove any consecutive spaces resulting from the replacement.
Constrain... | codefeedback |
Create a function that takes in a string and counts the number of vowels in it, while also considering uppercase vowels. The function should ignore any non-alphabet characters and spaces in the string. The function should return a dictionary that includes the count of each vowel found in the string. The function should... | codefeedback |
Write a SQL query to select the name, address, and salary from a given table, where the salary is greater than $50,000 and the employee has been with the company for at least 5 years. Table: Employee | codefeedback |
Write a program in Java to generate the Fibonacci sequence up to N numbers, where N is a positive integer greater than 1. However, you are not allowed to use recursion or any built-in functions or libraries to calculate the Fibonacci numbers. You must implement your own algorithm to generate the sequence.
Additionally... | codefeedback |
Implement an algorithm to find the sum of all the elements in an array, excluding any duplicate elements.
The array is: [3, 5, 8, 10, 4]
Constraints:
1. You cannot use any built-in functions or libraries to calculate the sum.
2. The array can contain negative numbers as well.
3. The array can have duplicate elements.
4... | codefeedback |
Design a function in Python to delete duplicates from a list, while also keeping track of the count of each duplicate element. The list is: [2, 3, 2, 4, 5, 5, 6]
Additional Instructions:
1. Implement the function without using any built-in Python functions or libraries.
2. The function should return a new list with th... | codefeedback |
Create a web page using HTML, CSS, and JavaScript that displays a div with some text. The text should change color every 2 seconds and rotate between a list of predefined colors. Additionally, when the user hovers over the div, the text should increase in size by 10%. Furthermore, implement a feature where clicking on ... | codefeedback |
Write a PL/SQL program to print out all prime numbers from 1 to 100 in ascending order. | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.